How do I stop enemies from overlapping (Pathfinding)

0 favourites
  • 5 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • I have a bunch of enemies with pathfinding.

    Unfortunately when they're walking along their path (they usually have the same target every time), they overlap one another. I'm not sure how to stop this from happening.

    I've tried setting each enemy as an obstacle, which causes lag.

    I've tried giving each enemy the solid behavior and 8direction behavior (this would usually cause the enemies to move out of the way of each other), but it lags.

    I've tried setting up an On Collision / When Overlapping event, where the enemy is teleported X -10 but that looks terrible.

    My question is how can I make the player move out of the way while still keeping it's current path? I have no objections to re-setting the path, I just want to have them move out of the way from each other if they were to overlap or collide.

  • I don't have my C2 available at the moment, but maybe you could try this:

    • check whether the enemy is near another enemy (through the "Is between two values" system condition). Alternatively, go with the "When Overlapping" condition though it might be a bit late when they are already overlapping
    • when that is true, just reduce the speed of one of the two enemies to zero.
    • add another condition, when the two enemies aren't next to each other AND one enemy's speed is zero (which selects that enemy), set its speed back to its original value

    If you encounter any problems or this doesn't work for you, I can setup a little capx for you.

  • Two ways off the top of my head, might not be the bestest solutions but work in a pinch...

    A) Use rex's PushOutSolid behavior and apply it to the enemies. Problem here is that you'll have to make the enemies solids and use custom pathfinding instead of around solids.

    B) Probably the easier one: use R0j0's Chipmunk physics and apply it to enemies. For some reason the default physics behaves all wonky when used together with pathfinding, but Chipmunk physics seems to work just fine. If this is a mobile game it might not be feasible, though.

  • I don't have my C2 available at the moment, but maybe you could try this:

    - check whether the enemy is near another enemy (through the "Is between two values" system condition). Alternatively, go with the "When Overlapping" condition though it might be a bit late when they are already overlapping

    - when that is true, just reduce the speed of one of the two enemies to zero.

    - add another condition, when the two enemies aren't next to each other AND one enemy's speed is zero (which selects that enemy), set its speed back to its original value

    If you encounter any problems or this doesn't work for you, I can setup a little capx for you.

    I'd really appreciate a capx if you ever find the time

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I tried to, but my solution doesn't work.

    If there were just two enemies, you could implement a short AI function to move the enemies away from each other when they are close.

    I tested my idea with 5 enemies and that didn't work.

    Sorry, I guess, you'll have to go with 's idea and try the Chipmunk physics.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)