Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using A* and still avoiding collisions?

I am designing a tower-defense game, and for that I am using the A* pathfinding algorithm to reach my destination from my spawn-areas.

The problem here is that all the units stack, which doesn't look visually good. Is there a way I can make them somehow group instead, and spread more if there's not enough space?

The algorithm works so that all units move a single tile at a time.

like image 318
Mathias Lykkegaard Lorenzen Avatar asked Apr 14 '11 11:04

Mathias Lykkegaard Lorenzen


1 Answers

A friend of mine who used to do AI design for a famous first-person-shooter game that you've probably heard of tells a story about how their pathfinding algorithm produced a fake-looking behaviour. You'd throw a grenade at a group of enemies in a constrained space, and they'd all bump into each other trying to all get on the efficient path to the single exit. It looked dumb and broke the illusion.

Rather than burning valuable processor cycles on better pathfinding, they added a heuristic such that if a group of enemies is fleeing, and an enemy bumps into another enemy twice in short succession, the enemy stops trying to flee and instead does a duck-and-cover, and then usually gets killed by the grenade as a result. It's very satisfying to the player, and looks a lot more realistic.

Perhaps there is something similar you can do here. If too many units end up heading towards the same path and are colliding with each other, and it looks unrealistic, is there some cheap and easy thing you can do to detect the situation and change the animation?

like image 78
Eric Lippert Avatar answered Sep 18 '22 15:09

Eric Lippert