Check if player direction(based on cone of defined angle) is oriented to target position.
900 {
901 if (player)
902 {
903 vector player_dir = player.GetDirection();
904 vector to_target_dir = target_pos - player.GetPosition();
905
906 player_dir[1] = 0;
907 to_target_dir[1] = 0;
908
911
912 float cos_fi =
vector.
Dot(player_dir, to_target_dir);
913 vector cross = player_dir * to_target_dir;
914
916
917 if( cross[1] < 0 )
918 dir = -dir;
919
921 if( (dir <= cone_angle && dir >= -cone_angle) ||
Math.
AbsFloat(dir) == 90 )
922 {
923 return true;
924 }
925 }
926
927 return false;
928 }
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.