Jump to content
  • Advertisement
Sign in to follow this  

player in AI bot view

This topic is 4906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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;
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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!