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
Answer by leomcpugo · Apr 22, 2019 at 05:42 PM
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 :)
void OnAnimator$$anonymous$$ove() {
var newDirection = Vector3.zero;
// if movement will be calculated by script
if (movementType == $$anonymous$$ovementType.Script) {
newDirection = getPlayer$$anonymous$$ovement();
// if movement will use the root motion of the animation
} else {
newDirection = enemyBase.animator.deltaPosition;
}
enemyBase.rigidBody.$$anonymous$$ovePosition(transform.position + newDirection);
}
Your answer
Follow this Question
Related Questions
Rigidbodies stopping Root Motion of animations 0 Answers
Kinematic ridigbody interferes with root animations and NavMeshAgent 0 Answers
Rootmotion fall 0 Answers
Later grab doesn't jump 0 Answers
Move 2 objects as one 0 Answers