- Home /
Why does my animation only play the first frame and just for a small fraction of a second?
So, I created a jumping animation for my 2D platformer character, and it seems to only play the first frame of it, and only for a very small fraction of a second. I used the Animator, and created a transition from "Any State" to my jump animation with the requirement that a bool called IsJumping is true. This is how I establish whether it is true or not:
if (Input.GetKeyDown(KeyCode.Space))
{
jump = true;
animator.SetBool("IsJumping", true);
}
...
public void OnLanding()
{
animator.SetBool("IsJumping", false);
}
I call OnLanding in an Event that triggers when the character is on the ground.
Yes, I remembered to uncheck Can Transition to Self. Thanks for any answers!
What does your animation look like when you play it? What does the transition setup look like?
I would also like to point out that instead of a boolean parameter, you could also use a trigger. That way, you don't have to manually reset it when you land; in fact, using input to set a bool to true
but then using an in-game event to reset it to false
seems rather arbitrary and inconsistent.
Answer by Foxxar · Mar 29, 2020 at 04:56 PM
I have the same problem now. Have you find out an answer?
Don't post an answer if it isn't an answer
Answer by Slaanesh40k · Aug 14, 2020 at 10:30 AM
@MrKathooloo I had this same problem and i believe we are using the same "charactercontroller" . Aight so the problem is that the moment you press the jump key you are still on the ground. this causes the "onlanding" event to trigger which turns off the jump animation. (i believe you will find if you double tap the jump button the jump animation will play mid air). this can be solved by making it so it only stops the jump animation every second time the "onlanding" event happens (meaning it wont stop the animation from playing as soon as you jump but will when you land from the jump)(u must take into account the first "onlanding" when the game starts). These are the changes and additions that fixed this problem for me:
public bool Testjump = false;
public int LandCount = 0;
public void Onlanding() {
if (Testjump == false)
{
if (LandCount == 0)
{
LandCount = 1;
}
else
{
Testjump = true;
}
}
else
{
animator.SetBool("isjumping", false);
Testjump = false;
}
}
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
Multiple Animation Controllers 1 Answer
My Animator is acting Strange 1 Answer
Use Humanoid Animations with aditional bones 2 Answers
Animation Vs Animator 2 Answers