I am playing around with Godot’s navigation system. I have enemies that chase the player, which works fine for my game.
But I also want to make it so that the enemies don’t stack on each other as they chase the player. There’s this avoidance option in the inspector, and I have tried it, and it works. But I don’t like how the default navigation avoidance works, it looks like the enemies are just sliding and pushing around each other instead of actually avoiding, by taking another route around each other(If that makes sense?). So I was wondering is there any alternative way of handling this? (programmatically)
It’s this option in the inspector that I am talking about, that I don’t like. I want to find a different way of handling the avoidance.
This can be a tricky topic but is a good question.
In my last game I had flocking behaviour implemented so I used several raycasts to be the enemies eyes, and used them to instigate avoidance when they got too close to others (and to do following once they had someone in sight too). So raycasts are an option for you.
If you are using pathfinding, you could also include the enemies as path blockages, so the path finding routes around them. This can be expensive to do however and will depend on how many enemies you have and your game requirements to see if it is possible.
Alternatively, and relatively simple to implement, is if your enemy is far away from the player, rather than just using the player position as a target, add some randomness to the enemies target, so they are all heading towards the player but aiming for different targets around the player. This is sometimes enough to keep them from stacking. The max distance you randomise to you can test, and also you could remove the randomness if they get close enough to the player. This simple method can have a big impact on removing stacking.