Check if player direction(based on cone of defined angle) is oriented to target position.
833 {
834 if (player)
835 {
836 vector player_dir = player.GetDirection();
837 vector to_target_dir = target_pos - player.GetPosition();
838
839 player_dir[1] = 0;
840 to_target_dir[1] = 0;
841
844
845 float cos_fi =
vector.
Dot(player_dir, to_target_dir);
846 vector cross = player_dir * to_target_dir;
847
849
850 if( cross[1] < 0 )
851 dir = -dir;
852
854 if( (dir <= cone_angle && dir >= -cone_angle) ||
Math.
AbsFloat(dir) == 90 )
855 {
856 return true;
857 }
858 }
859
860 return false;
861 }
static float Dot(vector v1, vector v2)
Returns Dot product of vector v1 and vector v2.
proto float Normalize()
Normalizes vector. Returns length.
static proto float Acos(float c)
Returns angle in radians from cosinus.
static const float RAD2DEG
static proto float AbsFloat(float f)
Returns absolute value.