The one about rigidbody (kinematic or not) and root motion animations

Hello!

I’m developing a beat em up game, it’s a 3D world with 2D sprites, and I would like to mix script movement (it works fine) and root motion movement (not working fine).

  • I’m using a non-kinematic RigidBody to move my character around so it won’t collide with walls, but animations (vertical) root motion is ignored
  • When I set my rigidbody to kinematic, the full root motion is applied but now it can move inside walls (and I don’t wan’t this)
  • All animations are created inside unity, as they are just sprite renderer + some transform.position for complex move pattersn

(PD: yes, I’ve checked the “Apply Root Motion” option)

Unity community, could you help achieve script motion + root motion + walls colliding?

Regards

So I found the answer, I’m using OnAnimatorMove to handle the root position movement by script, and rigidBody.MovePosition to move the character around and still keep collisions
You would want to do something like this

`void OnAnimatorMove() {
var newDirection = Vector3.zero;

// if movement will be calculated by script
if (movementType == MovementType.Script) {
    newDirection = getPlayerMovement();
// if movement will use the root motion of the animation
} else {
    newDirection = enemyBase.animator.deltaPosition;
}
enemyBase.rigidBody.MovePosition(transform.position + newDirection);

}`

I hope this is useful to someone there :slight_smile:

void OnAnimatorMove() {
var newDirection = Vector3.zero;
// if movement will be calculated by script
if (movementType == MovementType.Script) {
newDirection = getPlayerMovement();
// if movement will use the root motion of the animation
} else {
newDirection = enemyBase.animator.deltaPosition;
}
enemyBase.rigidBody.MovePosition(transform.position + newDirection);
}