Sign in to follow this  
Bruno

player in AI bot view

Recommended Posts

Hi, I can already cast a ray from the bot, and detect if the bot has ray of sight to the player. Now i wanted to make it, so that he only sees the player, when he his in the bot fustrum. I have the current angle the bot is facing, his position and direction, and the player position. Is there a easy way to find, for example the angle the player makes with the bot? this way, if the player angle between the bot was in the interval (>0 && <90) && (>270 && < 0) degrees , this would mean he would be somewhere in front of it, right ? thanks

Share this post


Link to post
Share on other sites
The piece of information that will help you solve this problem is that the dot product of two normalized vectors is the cosine of the angle between them. Using this, you could write a function like the following:


bool Visible(const Vector2& eyePos, const Vector2& eyeDir,
const Vector2& targetPos, float fov)
{
// Get dot product
Vector2 diff = targetPos - eyePos;
diff.Normalize();
float dot = diff.Dot(eyeDir);

// Clamp, just in case
if (dot > 1.0f)
dot = 1.0f;
else if (dot < -1.0f)
dot = -1.0f;

// Get angle
float angle = acos(dot);

// Determine visibility
return angle < fov * 0.5f;
}



Note that eyeDir is assumed to be normalized, and fov is in radians.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this