transform.InverseTransformPoint not working correctly in 2019.3.1f1
Not sure if this is a bug, or if I'm just being stupid but, according to the docs:
transform.position is the world space position of the transform. (example: -3.5, 1.7, 2.0) transform.localPosition is the local position of the transform. (example: 0.0, 1.7, 0.0) transform.InverseTransformPoint Transforms position from world space to local space.
So then, how come transform.InverseTransformPoint(transform.position) == (0.0, 0.0, 0.0) instead of (0.0, 1.7, 0.0)?
How come transforming my world position to my local position gives me a different value?
Is this a bug? What's going on here?
Answer by BrainSlugs83 · Feb 15, 2020 at 02:57 AM
Figured it out -- transform.InverseTransformPoint does not transform to localspace, it transforms to localspace as a child. -- e.g. where 0,0,0 is the same position as the parent. -- so if you want localspace, you have to use transform.parent.InverseTransformPoint.
I wish I would have seen this a few hours ago! I was confused as well. Thanks for posting your solution!
I got stuck on this for quite some time myself... Thanks for figuring it out!
Your answer
Follow this Question
Related Questions
[Solved] Linear movement speed, reset position 1 Answer
Photon Multiplayer : position of client player is not getting synchronized. 0 Answers
SImple, but how do I check a game object's position in an If statement? 1 Answer
How to make an object move in the direction another object is facing on 2 axis? 1 Answer