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 entity476 · Jun 07, 2013 at 01:49 PM · transform.positionworld coordinatestransform.transformpoint

Why transform.TransformPoint(transform.position) prints differently than single transform.position?

From a script attached on an object, which actually casts a Linecast from itself to a "target" object, I instruct to print the following two statements:

print (target.transform.TransformPoint(transform.position));

and

print (target.transform.position);

The two print instructions give these information respectively:

(2*X, uncertain relationship*Y, 2*Z)

and

(X,Y,Z)

Both of the objects, the one with the script attached and the "target" are not parented to anything and their scale values are 1,1,1. They are also both the Cube GameObject. Isn't it supposed that both statements should print the world coordinates of the "target" object?

Do you think is possible to draw a conclusion from this data or it might be more complicated? Any guesses however? Thank you very much.

EDIT: I also tried the experiment to just have a script with only the print statements. Moreover, I asked it to print the same for the object carrying the script itself. I get the same result, only that in the second case, also the Y coordinate has a double ratio. So, I guess it has to do with the way I have structured the statements. In particular, any idea how the TransformPoint functions? Since the transform.position is rather straight forward.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by robertbu · Jun 07, 2013 at 02:15 PM

TransformPoint() translates a point from local space to world space. 'transform.position' is already in world space. The local position of an object will be Vector3.zero, so if you want to compare the two, use:

 print (target.transform.TransformPoint(Vector3.zero));
Comment
Add comment · Show 6 · 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 entity476 · Jun 07, 2013 at 02:24 PM 0
Share

That's great! Only any clue what causes this double ratio, when I write it like above?

avatar image robertbu · Jun 07, 2013 at 02:39 PM 1
Share

Say I had an object at (2,3,4). The TransformPoint() will take (0,0,0) and turn it into (2,3,4). That is, it translates (i.e. adds to) the point by (2,3,4). So if I feed (2,3,4) into TransformPoint(), I get (2+2, 3+3, 4+4) which is (4,6,8) which is (2*2, 2*3, 2*4) which is what you see in your print statements.

avatar image entity476 · Jun 07, 2013 at 02:41 PM 0
Share

Trying to explain my own concern, with the original statement, it's like we ask to tell as the world coordinates of a point, which is located a vector(transform. position) away from the transform.position of the current object. Therefore, it's two times these coordinates in the world system. I see… Now i'll try to implement it to my more complicated case. Thanks!

avatar image Bunny83 · Jun 07, 2013 at 02:42 PM 0
Share

Yes the clue that robertbu gives you:

  • TransformPoint : local space --> world space

  • transform.position: a worldspace position

  • TransformPoint(transform.position) world space (interpreted as localspace) --> garbage-space

From your "uncertain relationship" i can see that your object is only rotated around the x-axis. I could paint a diagram, but i don't have the time and this answer should already answer the question.

Try to understand what's localspace and what's worldspace.

avatar image entity476 · Jun 07, 2013 at 02:43 PM 0
Share

Oh, yes that's right! Thanks, your answer helped me to clear things out!

Show more comments

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

15 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 avatar image avatar image

Related Questions

World coordinates conversion to cell coordinates in tilemap 1 Answer

How to get max and min points of a game object on the x and z axis? 3 Answers

Change vertex's world position 1 Answer

transform.position any suggestions? 2 Answers

transform.position.x brings up error 1 Answer


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