Character vision in a 3D world


I am working on a small FPS-like game based very loosely off of the 3-d roaming ralph code pasted. I am stuggling with how to best simulate enemy/computer character’s vision. Right now I am casting a spotlight of a specified length. I also have a collision ray attached to each character/enemy. if the player is in that spotlight AND if the collision ray intersects the player’s collision sphere before anything else in the world, the enemy can see the player. (The collision ray is used to test to see if there is anything else in the world blocking the view of the player).

This works fine in very small flat world’s. The problem comes when using it on a large, hilly world. Essentially, even after pointing the enemy/character at the player, it is still possible for the ray to not hit the player based on the distance/angle of the enemy. This causes some really ‘blind’-like enemy behavior.

What I am thinking:
1.) Use multiple collision rays shooting off at different angle from the enemy.

2.) Shoot a ray only after the player is in the spotlight. The ray would then be shot directly from the enemy’s center to the player’s center (by calculating vector between the two)

Anyone have any other thoughts or better ideas for implementation?


You might look into the manual’s mention of PandaAI, which is artificial intelligence, sounds perfect for what you’re doing.

Hope this helps,

Actually, PandaAI is something entirely different. It’s about the Agents’ navigation through the world, not necessarily about their ability to notice the player and/or other characters.

Wolfire has an interesting video on the subject. … -changelog

What you’re doing and thinking of doing, cfsb78, seems a fairly standard approach. The important part is to shoot many rays, one per frame. This works way better than a single ray, and since you’re still doing only one ray per frame, the performance doesn’t suffer.