CVector3 enemyPosNormalized = enemy->GetPosition();
CVector3 playerPosNormalized = player->GetPosition();
enemyPosNormalized.Normalize();
playerPosNormalized.Normalize();
float d = enemyPosNormalized.Dot(playerPosNormalized);
if (fabs(acos(d)) > 45)
; // enemy sees player
else
; // enemy does not see player
Detecting whether enemies can "see you"
hi, i want my NPC´s to be intelligent, but at first, i need checking whether they can see you.
it works for blocking geometry already.
but i want to test if the viewpoint the enemy "looks at" is pointing at me, the player.
i have tried something like this to find out the angle:
unfortunately, this algo does not work.
can someone point me to the right way?
thanks
Gammastrahler
[edited by - Gammastrahler on June 13, 2002 2:42:47 PM]
You want to dot the vector from the enemy to the player, with the enemies view vector.
Death of one is a tragedy, death of a million is just a statistic.
Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.
It would also be easier to store the view range already in terms of the cosine/dot product, i.e -1 to 1. It would avoid the expensive cos call and you wouldn''t have to worry about the absolute value, as the cosine''s domain takes care of the left/right direction problem inherently.
----------------------------------
if (fabs(acos(d)) > 45)
----------------------------------
Also ''acos'' returns a value in radians, so the above line should be something like
if (fabs(acos(d)) > PI/4)
Stephen
if (fabs(acos(d)) > 45)
----------------------------------
Also ''acos'' returns a value in radians, so the above line should be something like
if (fabs(acos(d)) > PI/4)
Stephen
Wouldn`t you want a view frustrum type thing.
Similar to the camera in gfx ?
"Just" have a truncated cone, then check if any player poly are within it ?
Bugle4d
Similar to the camera in gfx ?
"Just" have a truncated cone, then check if any player poly are within it ?
Bugle4d
~V'lionBugle4d
my engine currently uses no partitioning system (since it is in a very early development stadium).
but i plan to implement a portal engine for my inside areas and something other for my outside areas.
a view frustum for enemies would be a good idea (very accurate, i think). but would it be fast??
thanks
Gammastrahler
but i plan to implement a portal engine for my inside areas and something other for my outside areas.
a view frustum for enemies would be a good idea (very accurate, i think). but would it be fast??
thanks
Gammastrahler
I''d just do d > 0.707, i.e. d > sqrt(2.0)/2.0.
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Python_Regious has the best idea. We used the vector from the NPC to the Player, then compared that to the NPC''s current sight cone. ( our cone is a vector for direction that the NPC is facing, and the stored cosine values of the pitch and yaw of the cone). I wrote a function called pointincone, that took the player''s position, and created the vector to the player, did the dot product for the yaw, and b/c this vector is normalized, only had to look at the z value for the pitch.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement