Awareness of surroundings
Hi,
I''m in the process of writing a small demo using a state machine based system for controlling a sentry type unit.
The unit is supposed to patrol a given path and depending on how many enemies, if any, he encounters either give chase (but never beyond a certain distance from base) or fall back and defend.
I have in place the basics of a state machine and message router but I am wondering what the best way to deal with the unit''s awareness is? How will he know when units are near?
I see two possibilites, each with their own problems...
1) The sentry unit checks against all other entities in the world to see if they are within his line of sight, this is too slow and inefficient for my liking but it''s simple.
2) Other units check if they are entering the sentry''s field of vision when they move and send a message if they are. My problem with this is that every other unit in the world needs to know where the sentry is and how far he can see at all times. I was hoping to keep the sentry class as encapsulated as possible.
Also, this still isn''t particularly efficient!
Is there any better way of doing this, or is option 2 my best bet?
Thanks,
Forxl
--:D, F
March 31, 2001 05:17 PM
When an enemy sets foot on a tile, the tile is marked with its id. Then the sentry just checks the tiles in its LOS and if there is an enemy, it knows which one it is immediately, and where it is.
April 03, 2001 12:18 AM
Break the world into a 2d grid.
For each cell in the grid, create a list of entities/characters.
As entities move from cell to cell, add/remove them from the appropriate lists.
When processing each entity, check the lists of the surrounding cells..
You can easily increase the visibility range by checking further and further away from the primary entity/cell, and you ONLY process those that are valid..any entities that are out of range would never be encountered in the surrounding cells, and wouldn''t even hit the cpu![](smile.gif)
For each cell in the grid, create a list of entities/characters.
As entities move from cell to cell, add/remove them from the appropriate lists.
When processing each entity, check the lists of the surrounding cells..
You can easily increase the visibility range by checking further and further away from the primary entity/cell, and you ONLY process those that are valid..any entities that are out of range would never be encountered in the surrounding cells, and wouldn''t even hit the cpu
![](smile.gif)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement