- Home /
InverseTransformPoint not equal to the position in World to Local Matrix?
Hi All,
I'd like to ask how the inverseTransformPoint works. Suppose I have a gameobject with position (33.0, 25.0, 20.0) and the same orientation w.r.t world coordinates (with the scale 1). Then, the position of world coordinates w.r.t to the local coordinates of my gameobject would be (-33.0, -25.0,-20.0).
But, when I do the InverseTransformPoint to the position of my gameObject, the position of World to local are totally different from World To Local Matrix.
does anyone know what is the difference?
Thanks in advance
Answer by Owen-Reynolds · Dec 10, 2014 at 06:01 AM
You're probably using the matrix incorrectly. But figure the correct value, and see who's wrong and right.
Take your object p1 at (33,25,20). For simplicity, keep it "unspun" facing +Z. If you have point p2 at z+1 -- (33,25,21) -- then InvTransPoint should give you (0,0,1). Just to be clear, it's saying that p2 is one unit in front of p1. If you spin p1 to face right, then InvTransPoint should give you (-1,0,0). Again, to be clear, it's now saying that p2 is just to p1's left.
Try it again with the worldToLocal matrix. Should give the same numbers.
Hi Owen, thank you very much for your feedback. I understood the example you provided. But, suppose if a camera in world coord (33,25,20). I'd like to find the position of world coord w.r.t camera.
var cam = Camera.main.transform;
var Wtocam = transform.InverseTransformPoint(Vector3(cam.position.x, cam.position.y, cam.position.z));
As far as I understand, the Wtocam must be (-33,-25,-20). But the returned value from InvTrsPoint is completely different. Do you know what's the problem here?
Thanks
?? That second line gives how to go from the player (if the script is on the player) to the camera in the player's local coords. That what InvTransPoint does. If figures out local coords.
To get world coords from player to camera, just use transform.position - camera.position
. If the player has no extra rotation, they will be the same.
Local vs. World is a slippery concept. Helps to draw pictures, and focus on the end result.
that's right.
var pos= transform.InverseTransformPoint(transform.position);
I've tried doing the InvTransPoint to the position of object itself (in WCS) to see if I'll get the pos of World coordinate w.r.t to the local coordinates of the object. But it turns out zero numbers. This result due to the multiplication of Inverse matrix to the matrix itself is zero.
Thank you Owen for your time for giving this explanation.
Your answer
Follow this Question
Related Questions
Gross "Almost zero" Vector components when adjusting to local space and custom handles 2 Answers
Can't convert Bounds from world coordinates to local coordinates 6 Answers
rectTransform.InverseTransformPoint(rectTransform.position) is non-zero? 0 Answers
rotating a game object relevant to the face it on, on another game object 0 Answers
TransformPoint returns wrong points? 1 Answer