Collision problem between two enemies

20210619_183247
Hi guys, i made enemies that use pathfinding movement, but when they’re close they overlap.
Could you help me find a way to avoid the thing that happens in the video?
Maybe change the direction when they colline or slow down the speed?

Try to add a pathfinding obstacle behavior…
If that doesn’t work then try
separating enemies.
Or you may deactivate and activate behavior one instance of enemy, and that may change its direction(not sure haven’t tried).

Make a new action, type “separate” into the search bar and use the move blank away from blank action. Works perfectly for me

I had already triggered this event in the video sent.


Obstacle for pathfinding it seems not to work

Pathfinding is deigned to be for path from a to b avoiding pathfinding obstacles The pathfinder and the obstacles are 2 different objects. In your case these need to be the same, so the obstacles also happen to be pathfinding objects. And it doesn’t appear that GDevelop can have or can handle both behaviours on an object.

An idea which I haven’t tried this, and it may not work:

  1. get rid of the separate enemies event.
  2. Make a new object the same size as the enemy and add pathfinding obstacle behaviour to it.
  3. For each enemy, create an instance of this new object and link them
  4. Run the pathfinding move to action every frame (i.e use a for each without a condition) for every enemy. As you iterate through each enemy:
    a) position the linked obstacle off screen.
    b) perform the pathfinding move
    c) reposition the linked obstacle linked to the enemy

This may work, I’m not sure. And it has the potential to be a drag on performance. But it’s worth a crack.

I think the pathfinding obstacle will always cause issues.

However, I remember a similar question to this a while back for Triarite on the discord.

The recommended solution there was just do an event checking for the furthest away from the pathfinding target, then setting the speed to 0.
“pathfindingobjectname is in collision with pathfindingobjectname” and “Pick the pathfindingobjectname nearest to targetdestinationX;targetdestinationY (Inverted)”

Then just set the speed to 0 as the action. It’ll stop moving until it’s no longer in collision.

You can try this in the pathfinding AI example with the following setup:

4 Likes