Avoid pushing NPCs

,

Hello!
I have been following the RPG course and made some changes to it. I’m using a Player Controller (gamepad input) to move the character around with a Navmesh Agent Component. The enemies also have a Navmesh Agent to move around.
The problem is that the player can push NPCs around, the NPCs rarely push the player, because they have a stopping distance that avoids it.
(Adding a Rigid Body to a Player Controller is a nightmare, nothing works properly).

Player: brighter knigh.
Enemy: darker knight.

1 Like

While we’re not supporting gamepad input in this course, I’ll see what I can think of. The first thing that comes to mind is to do a raycast one unit ahead in the desired travel direction. If the Raycast turns up with an enemy in it, abort the movement.

Rigidbodies are commonly added to 3rd person player controllers. What’s happening when you add a Rigidbody to the player?

The character gets “heavy” (No gravity, is kinematic), moving slowly.

Hmmm… sounds like something isn’t working the way it’s meant to. Can you paste in your movement script, and perhaps a screenshot of your RigidBody settings as well? Let’s see what we can do to get it running correctly.

I found out the problem but cant work on a solution yet, is not in the movement, but in some animation, like rolling, attacking, and backstep, because I’m using Root Motion for those.

The setup for the Rigid Body is Default Gravity.disabled and Kinematic.enabled.

If I disable the Gravity and Kinematic option, root motion plays fine, but everything gets weird (because I’m affected by gravity).

It sounds like something like I first suggested would be the best way to go… running a raytrace out from the player towards the direction the player is moving, disabling movement if an enemy is too close.

In terms of the normal setup for controller based movement, the norm is to have the gravity checked ON and isKinematic checked off.

Are you using the root motion as the source of your movements (set parameters, root motion moves the toon), or transform.translate (set parameters to have animator represent the movement). It’s important that you don’t mix these.

Only to specific actions. Moving and running are not root motion, but attacking, rolling, and evading are, because they block movement. Is not default in the animation, I set it when needed.

The other alternative that I have, is to add rigid bodies and a collider in a Child GO for npcs and the player, and deactivate the rigid body while root motion animations are playing.

But raycasting could be much easier. I’ll go for that alternative.

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