How do I stop enemies from overlapping (Pathfinding)

Get help using Construct 2

Post » Fri Oct 07, 2016 4:27 am

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.
B
25
S
10
G
1
Posts: 154
Reputation: 2,687

Post » Sat Oct 08, 2016 3:26 pm

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.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sun Oct 09, 2016 12:02 am

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.
B
52
S
24
G
18
Posts: 295
Reputation: 13,090

Post » Sun Oct 09, 2016 12:47 am

randomly wrote: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 :)
B
25
S
10
G
1
Posts: 154
Reputation: 2,687

Post » Mon Oct 10, 2016 11:55 am

@ChaoticShadow24

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 @SupWithThat 's idea and try the Chipmunk physics.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 14 guests