InverseTransformPoint, help with understanding it in a code.
So I understand TransformDirection and TransformPoint is very straight forward and people use it very frequently for getting relative direction. But I never quiet understood what the practical usage of InverseTranformationPoint other than to undo a TransformPoint.
I came across this piece of code:
public static Vector3 ClosestPointOnSurface(BoxCollider collider, Vector3 targetPos)
{
// Cache the collider transform
var ct = collider.transform;
// Firstly, transform the point into the space of the collider
var local = ct.InverseTransformPoint(targetPos);
//...
So he just straight up InverseTransformPoint, which I don't understand what this is supposed to do. (I don't understand the comment either, because you could've just gone
targetPos - ct.pos
I'm played around with it for hours and read several post but still couldn't understand it's deal. Please help me senpai sama!
http://docs.unity3d.com/ScriptReference/Transform.InverseTransformPoint.html
Answer by karl_jones · Jan 21, 2016 at 11:35 PM
Its basically getting the position as a local position. targetPos - ct.pos would not account for scale and rotation so if the collider was scaled or rotated the value would be wrong. Try it out. Use a Gizmo to draw a line to the point and see the difference between targetPos - ct.pos and InverseTransformPoint . Its a nice learning exercise.
Your answer
Follow this Question
Related Questions
Array with pushing values? 0 Answers
Converting int into textmesh string (c#) 1 Answer
OnTriggerEnter 1 Answer
Running 'helper' programs, 0 Answers