Casting rays for enemy sight

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
anarkavre
Posts: 27
Joined: Mon Mar 08, 2004 9:57 pm
Location: PA
Contact:

Casting rays for enemy sight

Post by anarkavre »

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."
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

Possibly with getRayFromScreenCoordinates()

Look here http://irrlicht.sourceforge.net/docu/cl ... er.html#a3
Caecus
Posts: 36
Joined: Fri Aug 22, 2003 6:33 am
Location: California, USA

Post by Caecus »

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.
WickedImp
Posts: 8
Joined: Tue Mar 16, 2004 10:49 am
Location: C=DE/ST=NRW/L=Blankenrode

Post by WickedImp »

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...
Serg Nechaeff
Posts: 162
Joined: Wed Nov 26, 2003 5:24 pm
Location: Europe

Post by Serg Nechaeff »

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
anarkavre
Posts: 27
Joined: Mon Mar 08, 2004 9:57 pm
Location: PA
Contact:

Post by anarkavre »

How would I set the fov for a animated scene node, attach a camera as a child to it and set the fov?
"Without curiosity and knowledge, the mind is a vast void. Without the mind, curiosity and knowledge are nonexistent."
Mercior
Posts: 100
Joined: Tue Feb 24, 2004 1:53 am
Location: UK
Contact:

Post by Mercior »

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)
Post Reply