Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Field Of Vision [PB Src]

Author
Message
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 27th Jan 2008 17:42 Edited at: 12th Aug 2010 00:19
Field Of Vision / Field Of View (FOV) (Game AI)

The aim of this example is to demonstrate one method for detecting if the Player (or Actor) is within another actors view, aka Field Of Vision (FOV).

You can imagine the FOV of a PIE shape area attached to the actors position. The shape would look a lot like head lights from a car at night. To represent this pie shape area we need two things, the width of this field of vision in degrees and our maximum view range (how far can this character see?). The latter is not essential, but it's often those little extra's we include in our actor's behavior, that will (in the long run) enable us to create more balanced computer controlled opponents. There's nothing worse than when the actors in a game have perfect aim or
know insanely where you are within the game arena.

To determine if one actor can see the another, all we're doing is finding the direction (angle in degrees) from the actor to it's target. Once we have this, it's just a matter of finding the difference between the Actors current direction and the direction towards the target,

i.e.
AngleDiff#=AngleDifference(ActorsAngle#,AngleToTarget#)).

To determine if the target is potentially within our view, we just check Angle Difference is lower than the width of this actor FOV, if it is, it's potentially inside. To be sure, we need to check the distance between actor and the target, if it's within the FOV view range, then this target is with the actors FOV.

The demo represents the game actors as rotating blobs, with a pie shaped polygon shape attached representing the actors FOV. The player is simply the mouse pointer. The behavior of the actors is much a radar in this example. As such, if the Actor is unable to see the Player, it will happily sit and rotate right (clock wise), but if the players moves in front of the Actor, then the actor will try and turn towards the Player.

Well, that's about it... Have fun !


Downloads
playbasic source codes


Related Posts
Line Of Sight

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-05-17 09:00:47
Your offset time is: 2024-05-17 09:00:47