player with mixamo animation floating when going down the stairs
I have a character from mixamo with a rigidbody. I am controller the movement with rigidbody using a joystick pack. Basically I am checking if there is movement and in the joystick and if there is then a running animation plays and the player moves.
public void FixedUpdate()
{
forward.y = 0f;
right.y = 0f;
forward.Normalize();
right.Normalize();
var desiredMoveDirection = forward * verticalAxis + right * horizontalAxis;
if (joystick.Horizontal != 0f || joystick.Vertical != 0f)
{
animcondition = 1;
myRigidBody.rotation = Quaternion.Slerp(myRigidBody.rotation,
Quaternion.LookRotation(desiredMoveDirection), 0.15F);
myRigidBody.velocity = desiredMoveDirection * moveForce * Time.deltaTime;
}
}
Root motion is applied in the animator. Everything was working perfect until I added stairs. Going up is not an issue but when going down the gravity does not apply until I stop moving. I researched this and saw that applying "GravityWeight" to the curves in the animation and setting that to a 1 fixes the issue, however I tried that and it did not do anything. I tried using character controller with the rigidbody but that also did not work, I have also tried checking "Foot IK" in the animator for the running animation but that also did not help. another thing I tried was setting update mode in the animator to animate physics but then the player could not move
Is there anything i can do to keep the player grounded when going down the stairs? Any help would be appreciated, I am not sure what else I can do to stop the player from floating when running down the stairs.
Thank you!
Answer by BradyIrv · Jun 15, 2019 at 11:25 PM
I think it's because you're setting the velocity directly and the velocity.y is not affected by your input, therefore remains 0. Try,
Vector3 desiredVel = desiredMoveDirection * moveForce * Time.deltaTime;
myRigidBody.velocity = new Vector3(desiredVel.x, myRigidBody.velocity.y, desiredVel.z);
Although I advise against setting velocity directly. It could have undesired/unrealistic effects on the physics.
Your answer
Follow this Question
Related Questions
How to play 'open door' animation on only one door? 0 Answers
Walk towards mouse cursor 0 Answers
Help with Enemy death Animation! 1 Answer
how to change the animation lengh by script? 0 Answers
Infinite Time inbetween if statements? 2 Answers