Calculating angles between two points in 3d space

22.3k views Asked by At

I have two points (cube game object) in Unity, P1(x,y,z) and P2(x,y,z) and I have to set the MainCamera position and rotation along the vector between P2P1.

I tried different methods but was not successful. All suggestions are welcomed. Thanks.

1

There are 1 answers

0
arturx64 On

We can find angle between 2 vectors according the dot production.
angle = arccos ( a * b / |a| * |b| );
where:
a * b = ax * bx + ay * by + az * bz
|a| = sqrt( ax * ax + ay * ay + az * az )
|b| = sqrt( bx * bx + by * by + bz * bz )
Or just use this method: http://docs.unity3d.com/ScriptReference/Vector3.Angle.html