Difference Between Transform.TransformVector and Transform.TransformPoint

My confusion arose in the following scenario:

transform a;
transform b;

Vector3 newPosition = NewLocalPosition(a);
b.position = a.TransformPoint(newPosition);

void NewLocalPosition(transform){
   based on some input ;
   return new local position of transform ;
}

Transform a was descendant of many parents and transform b had no parents.

I was attempting to set the global position of transform b to the global position equivalent of the calculated new local position of transform a. I had only used TransformPoint in the past and this was giving me unwanted results. After a few hours of fiddling around i realized that TransformVector gave me the results i was looking for. I dont really understand why one works and not the other.

I would really appreciate some clarity in what the difference is as I am unable to find a clear explanation anywhere. Thankyou.

There are three similar methods on transform: TransformPoint, TransformDirection, and TransformVector. The difference comes down to which aspects of the transform are used or not used when performing the transform:

TransformPoint is used, as the name implies to transform a point from local space to global space. For example, if the collider of a player is offset by half their height so that the transform position is at the player’s feet, to get the world space position of the collider center, it would be playerTransform.TransformPoint(collider.center) because that world-space position will change if any one of the player’s position, rotation, or scale changes.

TransformDirection is used to transform a direction. For example, if there were a friendly AI that always wanted to face the same direction as the player, it would set its rotation to Quaternion.LookDirection(playerTransform.TransformDirection(Vector3.forward)). There’s actually a convenience property on transform called .forward that does exactly this, but bear with me. This rotates Vector3.forward (which is 0,0,1) to face the direction of the player’s forward direction. So if the player’s rotation is in the default orientation, it will just return 0,0,1. But if the player were looking straight down, it would return 0,-1,0. Since TransformDirection only cares about the rotation, note that the magnitude is preserved.

And finally, there’s TransformVector, which seems to be the same as TransformDirection, but takes scale into account and will thus change the return value’s magnitude accordingly (and probably the direction too if the scale is nonuniform). I’m not actually sure what this is useful for, since my use cases always fall under the first two, but clearly you’ve found a use for it!