Game Development Community

Angle bewteen 2 vectors

by Ted Lilljegren · in Technical Issues · 02/17/2008 (11:19 am) · 1 replies

Is there some quick way to get the angle between 2 vectors? I know how to do it using maths n stuff, but i was wondering if there is already some built in function(in torqueScript) that does this.

Disclaimer: i have searched

#1
02/17/2008 (11:49 am)
Never mind, i found some functions that did just the trick. If someone else is interested in getting the angle between stuff, here is what i did:

%casterVector = VectorNormalize( %caster.getForwardVector());
%targetVector = VectorNormalize( %target.getForwardVector());

%dotVector = VectorDot(%casterVector, %targetVector);

%angle = mAcos(%dotVector);
echo("Angle: " @ %angle);

You get the angle in radians (NOTE: i know some of this stuff goes out to the kids, thats why i am explaining something that i know most of you guys know hundreds of times better than me) and you always get the least angle between the vectors.

Have not tested it yet. So it might not work.