Move RigidBody2d - top-down view

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Rednib

I have the following situation :

  • I have a player (KinematicBody2d) that is controlled via WASD-Keys
  • Enemies (RigidBody2d) moving towards the player

The problem:

  • I want the player to be able to push the enemies away when walking through them
  • the enemies can move (should move towards the player) and should also be able to push themselves away
  • however, the enemies shouldn’t be able to push the player around

For that the player is a KinematicBody2d and the enemies are RigidBody2d with mode character (to prevent them from spinning when they get pushed)
Now I need to move (and slide) the rigid body’s towards the player while they can push themselves away

When I set the enemy type to KinematicBody2d I can move and slide them towards the player, but then nobody is able to push them away. And a rigid body can’t be moved directly.

Can somebody help me?

:bust_in_silhouette: Reply From: Merlin1846

Rigid bodies cant be moved with move_and_slide use apply_impulse or similar.