Overlap of the enemy horde

Hi guys, I’m returning to this unsolved problem of mine for some time… how can I manage the overlap of enemies with pathfinding behavior?
some advice?

Can you explain what the game looks like or post a screenshot, gif or video link. That might help trigger some ideas.

this is what I’m using for the moment

when the enemy behind collides with the enemy closest to the player, he stops and then starts again later…but this isn’t good when there are multiple enemies chasing the player.
I’ve searched the forum a bit but haven’t found a definitive solution on this matter.


I could not find any good way to separate units while walking
I think only option for me and most likely you would move them in some pre defined squads
So i made them separate only when they stop
Would that be good for you?

It seems to be a difficult problem with few to no good solutions.

This is the closest I was ever to get. It used a delayed movement along with different destinations. I made it a while ago. I need to see if I can improve it with what I’ve learned since then. The obstacles also help because it causes them to take different routes.

try me: click anywhere to add a target

source: GitHub - doug13579/PathFinderSurroundEnemy: Gdevelop PathFinder Surround Enemy

My other idea is to use 2 objects. A hidden object that follows the path and a 2nd object that follows that object. The top object would be able to move off from the other object to dodge other enemies while still following the path. I never got this to work.

The only other strategies are to time the spawning and to spawn from different locations around the player so the paths are less likely to cross.

Edit: Opps. I didn’t notice that the image was from ZeroX4. My ideas might still apply.

I saw the gif of your game after making my suggestions. What are the rules? Is it every team against every other team?

Are they targeting the nearest opponent or specific ones? It would be interesting to link pairs together and move them to the center point between them or another random location. As long as there were other enemies only 2 would fight each other at a time. You could use object Booleans to track availability.

Maybe you could utilize hidden objects with the Pathfinder obstacle behaviors. A cost would cause some to try to avoid the areas around a fight or you could disable/enable the obstacle behavior selectively to create zones around fighters. It’s a shame it didn’t work with layers like the physics behavior. You could assign different obstacles to different characters. You could use team IDs on the obstacles and the characters and then selectively enable or disable the obstacles before triggering the move events. It might be best to use costs and make every zone passable but with a cost.

Maybe if you use a grid based movement. IDK.

I’d like to test a few concepts. If I have any success. I’ll share it. I’d like to better understand the strategy or plot of your game first.

It is very very early stage RTS im working on
So far you control all units but in the end they gonna be separate per color
Which will be able to be either your allay enemy or neutral type units

For me them stacking while moving is perfectly fine i only need them to separate when they stop

Download link

1 Like

I have a feeling you kind of need to accept a certain amount of stacking. The important part would probably be setting the z-order and maybe using a grid based movement to provide a little natural distance although that would also force some objects to perfectly overlap and disappear completely.

The game needs to be looked at from the perspective of it taking place in the real world. How would a fight IRL look? How would each person behave.

The trouble with pathfinding is that it’s “expensive”. It uses a lot of resources. So, you compensate by taking snapshots of the scene and create paths which are immediately out dated the second an object moves.

I like the idea of hidden obstacles. When a fight breaks out a hidden obstacle could be created. Objects inside the obstacle would either ignore it through cost or selectively disabling it before using the move action. Or maybe when they’re close enough they simply use forces to attack each other. A path wouldn’t be needed at that point. With the pathfinder disabled, the separate action could be used.

Fights happen in clusters with gaps around them to allow other people to move around and between them. Otherwise, it’s just chaos and almost like static or an abstract painting.

The Boids behavior can be used to separate objects smoothly and efficiently by disabling cohesion and alignment.

1 Like

sorry for my delay in replying but I was unwell yesterday… I had already searched the forum and seen your example @Keith_1357
I’ll try to implement it in my project to see if it works and I’ll let you know.
regarding the @ZeroX4 example I think it wouldn’t work in my case as it wouldn’t remove the problem of overlap when the enemies follow the player.

1 Like

no @Keith_1357 I don’t think it’s the solution for my project… I tried to modify your example first to fit mine but the enemies follow a free point around the player and not the player… I want the enemies to look for collision with the player to attack them while they stand around.
Do you think the use of a second physical object under each enemy could solve the problem or, given the numerous creation of enemies, could it delay the game?
while as recommended by @davy has anyone ever used the boids behavior? even if this would mean completely changing my project, I would prefer to leave the pathfinding behavior

I’ve only used the boids a few times. It was always to chaotic for me. I don’t have any other ideas.

Going by the example on the wiki page for the Boids extension, it appears to be a simple matter of changing the “Move to position” to an “Intend to move towards” action. Maybe a bit of parameter modification, but it would appear, on the surface, that it’d be an easy swap of commands.

@davy, would this be a reasonable assessment of the changes required from pathfinding to Boids extension actions?

in the meantime I tried to create a pathfinding obstacle object behind each enemy… it seems to work quite well if it weren’t for the enemy’s flip which creates vibrations when you can’t find the path

i had this problem a while ago. the only way i solved it was making all of them the same object and using different animations for health, damage logic etc, and then just putting a seperate objects action as the enemy object for both params

My other idea is to use 2 objects. A hidden object that follows the path and a 2nd object that follows that object. The top object would be able to move off from the other object to dodge other enemies while still following the path. I never got this to work.
@Keith_1357 what do you mean by this?

I also tried using the boids movement but I don’t like the way they move and I would have to change a lot of my project.

I tried this with the sticker behavior. It sort of worked. You can’t use the separate action on objects that use the pathfinder behavior bc on the next frame, it will push or snap back.

My concept was to use 2 objects. One would follow the path. The other would follow it. You could then move the top object around a little while the hidden object continued on the path. The top object would have some wiggle room.

The sticker kind of worked except the objects kind of all huddled together and they didn’t reach the final destination if there were objects in front of it. The objects would need to move back into alignment as if they were connected with a spring or bunjee cord. IDK if a joint would work or be practical.

When it gets close, it needs change tactics Maybe as reach their destination, an obstacle behavior gets enabled.

I’m wondering if it would be easier to handle the movement with forces or a combination of selective pathfinding and forces. A collision could cause the object to switch modes and then after a few seconds it could switch back to pathfinding.

The objects need to be self-aware. They need to be able to find open spots. I would try to flowchart it as if it was the real world.

The problem is the more realistic it gets, the more resources it will use.