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!
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.