simple math question
I''m starting to code my own ai system and was wondering how to find if an AI can see the player. Basically, I have the AI''s position, rotation and field of view as well as the players location and distance and need need to be able to find if the AI can see the player. I know this is going to need trig., but I''m not sure how.
Any ideas. *Any* help is appreciated.
I''m not a mathmatican but if the field of view is conic then check for a segment (polygon, bounding box) of the player in that cone. if the field of view is between two planes then check for the player in that area.
,Jay
,Jay
Ok. The ai only has to see in 2d. I was kinda looking for a more mathimatic way of determining weather the AI can see the player.
raytracing is the answer. i can''t give you details without seeing your engine, but basically you "look" along many lines that radiate out from the enemy (either 360 degrees, or a "wedge" shape FOV), and if the lines hit the character before they hit a wall (or other obstacle) or "run out" (they can only see a certain distance, right?) then they can see you. the number of lines you have to check depends on if the game is tile-based or not.
--- krez (krezisback@aol.com)
--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
ok, I was kinda thinking about that, but isn''t there an easier solution, like a formula that I can use? The player and the AI are both points, so I don''t have to figure out if the player if only half visible.
Thanks, though
Kevin
Thanks, though
Kevin
If you really want, you can check the distance of two points by:
sqrt( (x1 - x2) + (y1 - y2) )
it might be the two things inside squared, i can''t remember which anymore, too much stuff with conic sections cramed in my head!
||--------------------------||
Black Hole Productions
http://bhp.e-chrono.net/
Resident expert on stuff
max621@barrysworld.com
||--------------------------||
sqrt( (x1 - x2) + (y1 - y2) )
it might be the two things inside squared, i can''t remember which anymore, too much stuff with conic sections cramed in my head!
||--------------------------||
Black Hole Productions
http://bhp.e-chrono.net/
Resident expert on stuff
max621@barrysworld.com
||--------------------------||
||--------------------------||Black Hole Productionshttp://bhp.nydus.netResident expert on stuffmax621@barrysworld.com||--------------------------||
Actually, in addition to the whole distance thing (which, incidentally can be done much more efficiently by defining the max as distance squared and forgoing the sqrt), you can find whether the person is within a given field of view by getting the dot product of two vectors:
-Direction in which the NPC is looking
-The vector between the player and the NPC
If both these vectors are then normalized, the dot product will then return the cosine of the angle between the two vectors, and if that value is within the boundaries of the field of view the NPC can then "see" the player. This does not take into account the possibility that there is an object in the way, but that''s a much bigger problem to do efficiently. If you need to explore that as well, I would suggest doing a Google serach on "quadtrees."
The wind shear alone from a pink golfball can take the head off a 90-pound midget from 300 yards.
-Six String Samurai
-Direction in which the NPC is looking
-The vector between the player and the NPC
If both these vectors are then normalized, the dot product will then return the cosine of the angle between the two vectors, and if that value is within the boundaries of the field of view the NPC can then "see" the player. This does not take into account the possibility that there is an object in the way, but that''s a much bigger problem to do efficiently. If you need to explore that as well, I would suggest doing a Google serach on "quadtrees."
The wind shear alone from a pink golfball can take the head off a 90-pound midget from 300 yards.
-Six String Samurai
_________________________________________________________________________________The wind shear alone from a pink golfball can take the head off a 90-pound midget from 300 yards.-Six String Samurai
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement