- Home /
Jump animation isn't working while running
Hello, im trying to make a 2d game. when i press the space bar to jump, the jump animation is working correctly. but when i run and then press the space bar to jump (while im running), the jump animation isn't working. is just shows the run animation. can anyone please help me fix this problem?,Im trying to make a 2d game. when i press the space bar to jump, my jump animation is working correctly. but when im running and then press space to jump (while im running), the jump animation isn't working. can anyone please help me to fix this problem?
Answer by Koishi-_- · Sep 14, 2021 at 08:58 PM
Its probably because you have no transitions on the animator tab.
If this is the case, what should fix it would be making a transition from [Any state] to [Jump] in the animator, and setting said transition's conditions to [IsJumping = true]
Then, making another transition from [Jump] to [Idle], and setting that one's to [IsJumping = false] and [MovementSpeed < 0.001]
Hope it helps :)
have you disabled exit time? sometimes the transitions do take place but wait for the previous animation to end first, and we land in that duration, giving the appearance that the animation didn't work
yes I did disable exit time and still it doesn't work
Answer by JMasterBoi · Jul 17, 2020 at 01:11 AM
This also happened to me. This could be happening because you are using if
and else if
statements. this means that only one will happen at a time. You can fix this by having both of them being if
statements. If you want a better or more specific explanation you are going to have to show your code.
Answer by Abbas_1505 · Jul 17, 2020 at 09:24 AM
That is my PlayerMovement script but im also working with a character controller.
using Microsoft.Win32;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public CharacterController2D controller;
public Animator animator;
public float runSpeed = 40f;
bool jump = false;
bool crouch = false;
float horizontalMovement = 0f;
// Update is called once per frame
void Update()
{
horizontalMovement = (Input.GetAxisRaw("Horizontal")) * runSpeed;
animator.SetFloat("Speed", Mathf.Abs(horizontalMovement));
if (Input.GetButtonDown("Jump"))
{
jump = true;
animator.SetBool("IsJumping", true);
}
if (Input.GetButtonDown("Crouch"))
{
crouch = true;
}
if (Input.GetButtonUp("Crouch"))
{
crouch = false;
}
}
public void OnLanding ()
{
animator.SetBool("IsJumping", false);
}
void FixedUpdate ()
{
controller.Move(horizontalMovement * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
}
Brackeys right ? and yeah I got the same problem jump animation isn't work but when I press space botton for second time it start working and I wonder what should I do ?
Answer by skagontale · Sep 16, 2021 at 09:32 PM
make sure when you jump set running in the animator to false it is taking priority. set it to true when landed. i feel the best way to this is with an isGrounded bool and to dissable running when it is false
Your answer
Follow this Question
Related Questions
2D Animation frame selection 0 Answers
Having some stuck issues on the 2D infinite runner 0 Answers
How do you add a timed animation 1 Answer
Stuttering in simple 2D game using interpolation? 1 Answer
2D animation issue 0 Answers