Why does subtracting two positions give you a valid rotation to look at an object?

Specifically, I’m wondering about this piece of code:

Vector3 TargetLocation = Person2.transform.position - this.transform.position;

    Quaternion TargetRotation = Quaternion.FromToRotation(transform.forward,TargetLocation);

    this.transform.rotation = TargetRotation;

Why does it make you look at a target? Why does subtracting Person2’s POSITION from Person1’s POSITION give you the ROTATION make you look at a target?
Also, just to be clear, Quaternion.FromToRotation(transform.forward,x) is pretty much the same as Quaternion.LookRotation(x) , right? Thanks in advance.

Here’s a good read on vector arithmetic: http://docs.unity3d.com/Documentation/Manual/UnderstandingVectorArithmetic.html

1 Like

Your first line of code has a misleading variable name. That’s not the target location, it’s the direction vector between your object at the Person2 object.
You’re then converting that direction vector into a Quaternion which describes rotating to look in that direction.
nextremity’s link explains these basic concepts nicely :slight_smile:

1 Like