Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by thabigge5607 · May 24, 2013 at 06:02 PM · vectorlocalglobaltransformpointinversetransformpoint

TransformPoint returns wrong points?

I have some code where I take a global position, convert that with InverseTransformPoint to local. I then split that variable up into two variables, one subtracts from it and the other adds to it (the same value is subtracted/added). When this stage is done the difference between the two, locally, are (0.2,0.2,0.0). However, after converting it back to global the difference between the two are (-4.7,-0.8,-0.8).

I'm aware it's probably just my math or thinking that is off, but I thought I'd ask nonetheless. Does it return wrong points? Or is there some weird voodoo ritual I gotta do first?

Here's the code I use for converting and tweaking (info is a RaycastHit, radius is a Vector3):

 Vector3 localUpperRightCorner = (transform.InverseTransformPoint(info.point)+radius);
 Vector3 localLowerLeftCorner = (transform.InverseTransformPoint(info.point)-radius);
 Vector3 upperRightCorner = transform.TransformPoint(localUpperRightCorner);
 Vector3 lowerLeftCorner = transform.TransformPoint(localLowerLeftCorner);

localUpperRightCorner - localLowerLeftCorner = (0.2,0.2,0.0)

upperRightCorner - lowerLeftCorner = (-4.7,-0.8,-0.8)

X&Y on the latter is supposed to equal the previous one's.

One of my comments earlier:

Yes, I use a different scale. What I need done is to just plot out a small distance from one corner of the object to the other. The distance totaled to (0.2,0.2,0). This distance was plotted out on the surface of another object (thus the raycasthit). then I took those coordinates and made them into global, and they don't align themselves to what they should've. Which is the issue I'm facing.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · May 24, 2013 at 06:02 PM 0
Share

Posting your code help here.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · May 25, 2013 at 06:35 AM

I assume that radius is a Vector3. I put the following code in Update() and played with the position and rotation of the game object. The magnitude between the local and global coordinates was always the same. But if I change the Scale of the game object, the values were no longer the same, which makes sense. I'm guessing that the game object you have the script above attached to has a scale other than (1,1,1).

     if (Input.GetKeyDown (KeyCode.A)) {
         Vector3 localUpperRightCorner = (transform.InverseTransformPoint(transform.position)+radius);
         Vector3 localLowerLeftCorner = (transform.InverseTransformPoint(transform.position)-radius);
         Debug.Log ("Local Distance = " + (localUpperRightCorner - localLowerLeftCorner).magnitude);
         
         Vector3 upperRightCorner = transform.TransformPoint(localUpperRightCorner);
         Vector3 lowerLeftCorner = transform.TransformPoint(localLowerLeftCorner);
         Debug.Log ("world Distance = " + (upperRightCorner - lowerLeftCorner).magnitude);    
     }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image thabigge5607 · May 25, 2013 at 12:31 PM 0
Share

Yes, I use a different scale. What I need done is to just plot out a small distance from one corner of the object to the other. The distance totaled to (0.2,0.2,0). This distance was plotted out on the surface of another object (thus the raycasthit). then I took those coordinates and made them into global, and they don't align themselves to what they should've. Which is the issue I'm facing.

avatar image robertbu · May 25, 2013 at 03:07 PM 0
Share

You are going about this the long way. First, '`transform.InverseTransformPoint(transform.position)`' will always equal (0,0,0). Second the corners you are calculating for a cube will always be (0.5,0.5,0.5) and (-0.5, -0.5, -0.5) regardless of the scale of the cube. So you can do:

 Vector3 corner = new Vector3(.5f, .5f, .5f);
 Vector3 upperRightCorner = transform.TransformPoint(corner);
 Vector3 lowerLeftCorner = transform.TransformPoint(-corner);
 Debug.Log ("LL: "+lowerLeftCorner+" UR: "+upperRightCorner);
 Debug.Log ("Distance: "+(upperRightCorner - lowerLeftCorner).magnitude);

But for your original code to find the corners, your radius Vector3 would have to equal transform.localScale / 2.0 and be in global coordinates, so you don't have to do the TransfromPoint() at all. You can do:

 upperRightCorner = transform.position + radius;
 lowerLeftCorner  = transform.position - radius;
 Debug.Log ("LL: "+lowerLeftCorner+" UR: "+upperRightCorner);
 Debug.Log ("Distance: "+(upperRightCorner - lowerLeftCorner).magnitude);
avatar image thabigge5607 · May 25, 2013 at 07:27 PM 0
Share

I do do radius = localscale/2. And I haven't gotten the local coordinates of the object itself. The object is trying to get the local coordinates of a raycasthit (and it does). That way I can use local coordinates±radius to get where the corners of a square would be along the 1st object (the one that got hit by the raycast) itself, ins$$anonymous$$d of calculating the 1st object's rotation to get where the corners would be located.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to open and close a door parented to a rotating object? 0 Answers

How do I return local normals? 1 Answer

Local Rotation and then Global Rotation 1 Answer

Should I create local copy of global variable? 3 Answers

Use local direction for particle billboard type 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges