Casting rays for enemy sight
Casting rays for enemy sight
How would you go about casting rays for enemy sight. I thought about using an array of lines using line3f. Though does anyone have an example of the math involved in doing this.
"Without curiosity and knowledge, the mind is a vast void. Without the mind, curiosity and knowledge are nonexistent."
-
- Posts: 360
- Joined: Tue Feb 10, 2004 2:20 am
- Location: Lubbock, TX
Possibly with getRayFromScreenCoordinates()
Look here http://irrlicht.sourceforge.net/docu/cl ... er.html#a3
Look here http://irrlicht.sourceforge.net/docu/cl ... er.html#a3
Actaully what you want is scene::ISceneCollisionManager::getCollisionPoint() which can be found on the same page of the docs that smileman provided a link to.
As far as the math behind it... thats not quite as easy. You going to have to find one of the more math-types to explain it. The simplest idea I have of is to cast a ray (line) from the enemy and testing them against a representation of the player. Obviously this only checks whats directly in front of him. Now you could extend this idea to use an array of lines created using nested for loops simply change the angle of the ray slightly... I'm not sure if casting 4x4 or 10x10 rays for every enemy is very ideal though...
This same basic idea is actaully used in regular collision detection schemes as well... check out the game dev article Pool Hall Physics.. It talks about collisions between two moving objects of different size using rays.
As far as the math behind it... thats not quite as easy. You going to have to find one of the more math-types to explain it. The simplest idea I have of is to cast a ray (line) from the enemy and testing them against a representation of the player. Obviously this only checks whats directly in front of him. Now you could extend this idea to use an array of lines created using nested for loops simply change the angle of the ray slightly... I'm not sure if casting 4x4 or 10x10 rays for every enemy is very ideal though...
This same basic idea is actaully used in regular collision detection schemes as well... check out the game dev article Pool Hall Physics.. It talks about collisions between two moving objects of different size using rays.
The idea of casting 'rays' for collision detection is not bad at all. But I think if you 'raytrace' so many lines it will be a performance problem.
Here is what I have in mind from the good old quake-engine:
Every player (real persons and bots) have a FOV (i.e. 90°) you first should check if the target (i.e the real player) is in the FOV by getting the calculated degree difference between the view direction of your bot (in this case it is called self) and your target. if it is withing 90° then you can cast a ray directly from the eye of self to the eye of target. If this ray collides with something else in between than you cannot see the target.
Maybe this can be improved by casting rays to all edges of the bounding box of target. If one or more rays only collide with the bbox than you can partially see the target. This could also be used to say that self cannot exactly identify target if he only gets two positive rays
Hope this helps...
Here is what I have in mind from the good old quake-engine:
Every player (real persons and bots) have a FOV (i.e. 90°) you first should check if the target (i.e the real player) is in the FOV by getting the calculated degree difference between the view direction of your bot (in this case it is called self) and your target. if it is withing 90° then you can cast a ray directly from the eye of self to the eye of target. If this ray collides with something else in between than you cannot see the target.
Maybe this can be improved by casting rays to all edges of the bounding box of target. If one or more rays only collide with the bbox than you can partially see the target. This could also be used to say that self cannot exactly identify target if he only gets two positive rays
Hope this helps...
-
- Posts: 162
- Joined: Wed Nov 26, 2003 5:24 pm
- Location: Europe
also work only with enemies within a cartain distance
http://www.javazing.com
P-III-950, WinXP, GeForce FX5600 128 MB ForceWare 52.16, DX9, Eclipse IDE, JRE 1.6
P-III-950, WinXP, GeForce FX5600 128 MB ForceWare 52.16, DX9, Eclipse IDE, JRE 1.6
no the fov would be a value you store with your npc's - then you cast the ray between the player and the NPC, check if it doesnt collide and check that the line is within the NPC's field of view (their current angle +- 30 degrees or so)
.: http://www.mercior.com :.