PDA

View Full Version : According to a value, determine the angle between two vectors



mapleegreen
12-28-2011, 05:01 AM
function bool NeedToTurn(vector targ)
{
local vector LookDir, AimDir;

LookDir = Vector(Rotation);
LookDir.Z = 0;
LookDir = Normal(LookDir);
AimDir = targ - Location;
AimDir.Z = 0;
AimDir = Normal(AimDir);

return ((LookDir Dot AimDir) < 0.93);
}0.93 is how many degrees? If it is 45 degrees, 60 degrees, how much value should be?

Angel_Mapper
12-28-2011, 05:14 AM
Dot products are the cosine of the angle, so just arccos it.

Wormbo
12-28-2011, 07:59 AM
Note that the dot product only calculates the cosine of the angle if both vectors are normalized.

Angel_Mapper
12-28-2011, 08:10 AM
Those are the two rules of life:

1) Always normalize your vectors.
2) Never get involved in a land war in Asia.

mapleegreen
12-28-2011, 09:14 PM
I know ,thank you

mapleegreen
12-28-2011, 10:09 PM
I know ,thank you