• Create Account

Posted 03 January 2013 - 09:43 AM

If you are facing northeast, your direction vector would be in the direction of (+1, +1), normalised this gives (1/sqrt(2), 1/sqrt(2)).

The vector from you to an enemy is posEnemy - posYou so if you are at (10, 0) and an enemy is at (5, 5) then the vector towards them is (5-10, 5-0) = (-5, 5), normalised (-1/sqrt(2), 1/sqrt(2)).

Dot product between those vectors is -1/2 + 1/2 = 0.

This is the cosine of the angle between you, and cos(90degrees) = 0, so they are perpendicular to your facing.

If the dot product is 1, they are directly ahead of you (cos(0) = 1). If it is 0, they are perpendicular to your facing.

All you need to check is that the dot product is greater than the cosine of the desired half-angle of your cone.

Hope that helps.

EDIT: Maths fail, oops ;) Fixed now

Posted 03 January 2013 - 09:43 AM

If you are facing northeast, your direction vector would be in the direction of (+1, +1), normalised this gives (1/sqrt(2), 1/sqrt(2)).

The vector from you to an enemy is posEnemy - posYou so if you are at (10, 0) and an enemy is at (5, 5) then the vector towards them is (5-10, 5-0) = (-5, 5), normalised (-1/sqrt(2), 1/sqrt(2)).

Dot product between those vectors is -1/2 + 1/2 = 0.

This is the cosine of the angle between you, and cos(90degrees) = 0, so they are perpendicular to your facing.

If the dot product is 1, they are directly ahead of you (cos(0) = 1). If it is 0, they are perpendicular to your facing.

All you need to check is that the dot product is greater than the cosine of the desired half-angle of your cone.

Hope that helps.

EDIT: Maths fail, oops ;) Fixed now

Posted 03 January 2013 - 09:41 AM

If you are facing northeast, your direction vector would be in the direction of (+1, +1), normalised this gives (1/sqrt(2), 1/sqrt(2)).

The vector from you to an enemy is posEnemy - posYou so if you are at (10, 0) and an enemy is at (5, 5) then the vector towards them is (5-10, 0-5) = (-5, -5), normalised (-1/sqrt(2), -1/sqrt(2)).

Dot product between those vectors is -1/2 + (-1/2) = -1.

This is the cosine of the angle between you, and cos(180degrees) = -1, so they are directly behind you.

If the dot product is 1, they are directly ahead of you (cos(0) = 1). If it is 0, they are perpendicular to your facing.

All you need to check is that the dot product is greater than the cosine of the desired half-angle of your cone.

Hope that helps.