Advertisement

Pathing AI around other units

Started by March 15, 2010 06:42 PM
2 comments, last by Narf the Mouse 14 years, 8 months ago
I currently have a simulation of 'red' soldiers versus 'blue' soldiers in an isometric 2d situation. The soldiers attack each other by targeting an enemy, using A* to navigate towards it, and then melee attack when in range. My A* system only works on the map tiles which either can be navigated or are impassable. The AI enemy targeting targets the closest enemy unit. With this scenario, the rear units in the two opposing formations move to the front line to attack the closest enemy units, like the front line units previously did. So after some time there is unit bunching in large number battles. My objective is to eliminate this unit bunching. Some things I've tried: 1. Turn on collisions between like sided units (ie red collides with red) - this prevents the bunching, but the units still try to navigate their previously calculated attack path; they are unable to do so since another unit is blocking and then just simply keep trying to navigate until the clustering subsides. Doesn't work too well. 2. Then I added a system to reduce the number of units each enemy unit can be targeted by. This was unsatisfactory since units ignored other units at odd times. Less bunchy though. So I did some research and I haven't been able to find much info regarding pathfinding units avoiding other units. Some things I did find was to only regard non-moving units as stationary obstacles. This necessitates the A* path graph to be updated basically every frame since with many units there are always some units that will become stationary (to melee attack, for example) and units that were previously stationary that need to move again. So I am thinking the above paragraph indicates a possible solution. So I think I am going to try this, but I was wondering if any of this board's posters had any other ideas or things to try. I've tested updating my pathing graph each frame and it seems like I am able to do it and still have the game run fast enough. I am not really interested in expanding the system to avoid collision between two moving units navigating their calculated paths since this seems more complicated and not that much gained. Any ideas? Thanks.
You may want to search for flocking behavior. Avoidance is part of that behavior. Each unit has an invisible radius around them and the closer it is to another unit the greater it resists travelling that same path.
Advertisement
Quote: Original post by chuck22
You may want to search for flocking behavior.

I was already familiar with it having spent some time on Craig Reynolds' over the past year or so. It's just that I got stubborn trying to push thru my insufficient solution instead of using the simpler and more elegant flocking behavior.
Quote: Original post by chuck22
Avoidance is part of that behavior. Each unit has an invisible radius around them and the closer it is to another unit the greater it resists travelling that same path.

Okay, I'll give this a try. Thanks for the suggestion. The problem seems to solve itself this way. Damn tunnel vision.
Another option is just to do quick pathfind from where they are to the next unblocked tile on the map, when they run into an obstacle.

Also, it may be a good idea to re-pathfind every so often, especially as things get crowded.

This topic is closed to new replies.

Advertisement