Pushing NPCs away while walking

The idea is to have movement similar to Vampire Survivors where NPCs push each other and the player can push its way through a mass of NPCs.
Is there a setting/component that allows it or do I have to program that behavior on my own?

Video for reference https://youtu.be/wgYu6lLi6cE?si=R54zy8-fIlmH9pZe
Keep an eye in the cloud of bats at 4:51 and that is the behavior I’m looking for.

Bump

Add velocity to the movement component.


But then, you may not be using a movement components if you want 100s on-screen NPCs. The actual solution would need to stem from the method of movement implementation. What’s the plan to move stuff around?

For now I’m using MoveTo from the Behavior Tree for moving the NPCs.

So a movement comp on a navmesh. →

This would move an NPC regardless of what they’re up to and still respect collision. As in, imagine the swarm of bats taking the Zombie with them and ramming it into an obstacle they, themselves, can fly over.

Do you mean by using Add Impulse?

No, add to the velocity or override it. Adding impulse could also work since the movement comp understands it. But velocity is more of an override, it will ignore ground friction, their need to walk in a specific direction, animation and so on. Whenever pawns move, they generates velocity, you can override it with:

Take the velocity of the Bat => apply it to the Zombie - now they’ll move together. Have a look:

You can shove characters with it.


  • you could get fancy with it and tell the Zombie to MoveTo where the bats are moving instead
  • or you could Apply Movement in the direction of the bat movement for as long as the bats are nearby (overlapping?)

The video is just an example. The idea is that the player can push through the NPCs the same way.

Anyways, setting the velocity doesn’t work when the player is surrounded because it generates collisions between the NPCs and nothing moves xD

I’ll probably need a flag to say that a pushed NPC can’t be pushed again.

  • get input direction and apply velocity / force in said direction direction, you’d push stuff away without even touching it. With a sphere overlap, perhaps. Or apply it on capsule collision.
  • you can disable physical interactions on select movement components so the undesired entities do not apply force on the player
  • this is new in UE v5.5:

You can exclude the player from the simulation, they will not be blocked (that easily anymore).

This is what I’m doing right now

I’m not simulating physics. I think it will be too costly with a high number of NPCs

You are doing something even more costly - not only does the movement comp emulate it, but it also has a huge overhead. That’s why my initial question / query included:


Scrub and see if it makes any sense:

I’ll take a look.

1 Like

Marching forward:

Not great. With pushing:

Crude, can be done better, but that’s the gist. The method, once improved, could work fine on a smaller scale.

@Everynone Thanks for the help. It actually helped :smiley:

I have used your suggestions as starting point and ended up with the following solution:

  • Multi Sphere Trace from the position in the past tick to the possible end position in the current tick based on Velocity
  • move all hit actors away with SetActorLocation calculating the distance between them using their collision radius




1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.