# 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.

## 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 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 on other sites
thanks, it worked just fine :)

1. 1
2. 2
Rutin
22
3. 3
JoeJ
20
4. 4
5. 5

• 27
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631735
• Total Posts
3001941
×