- Home /
How do I get the fall animation to only play when the player is falling and then go back into an Idle when player is grounded again?
what is happening now is when the player is grounded and I hit space the player will jump and the jump animation will trigger fine but as soon as the player is not grounded the Falling animation will trigger and keep looping even if the player is grounded so my question is what is wrong with my code as I know the animations are set up properly in the animator? Here is my code.
if (isGrounded)
{
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
_animator.SetTrigger("IsJumping");
}
if (!isGrounded)
{
_animator.SetBool("IsFalling", true);
}
else
{
_animator.SetBool("IsFalling", false);
_animator.SetBool("Landing", true);
}
Answer by xxmariofer · Feb 07, 2019 at 08:01 PM
change the code to this
if (isGrounded)
{
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(jump* jumpForce, ForceMode.Impulse);
_animator.SetTrigger("IsJumping");
}
else
{
_animator.SetBool("IsFalling", false);
_animator.SetBool("Landing", true);
}
}else
{
_animator.SetBool("IsFalling", true);
}
Your answer
Follow this Question
Related Questions
How Can I get the mouse to Cycle Through Animations Each Time I click it? Please Help! 1 Answer
Record a specific movement of a gameObject, then save it as an animation in Unity? 1 Answer
Issue with mecanim playing an animation using setbool 1 Answer
(2D) What is the best way to implement a run-and-shoot animation? 1 Answer