- Home /
Jump and fall animations not working
Hey there, I just made a game with some jump and fall animations but they won't work it looks to me like they are repeating themselves before they're finished. I unchecked any loop options and also unchecked can transition to self, my code is working fine I'm sure about that but it might be something with Animator tab settings? I have no clue, can someone help me?
Video of gametesting: https://youtu.be/sFkROilMR0c
Answer by Kristifor_p · Oct 27, 2019 at 11:35 PM
Okay i have seen your test video, and yeah you didn't set up your animator correctly.
You need to make transition to your jump animation from any state.
Make sure you added transition to true when you click specific button correctly in your script, if you have it please share it so i can review it.
Make sure the transition time is 0 between animations in 2D games.
Follow this steps and let me know if they worked for you!
Answer by Matthias1590 · Oct 28, 2019 at 07:22 AM
@Kristifor_p Thank you for replying! But it's not working yet. it shows me something, but it's still repeating the first frame or something I made a new video: https://youtu.be/wtq4s7nqM58 (the framerate is just timed badly so when you see it fall it flashes between the animations real quick and when u don't see it fall it's just timed so u only get to see the not falling flashing parts)
Here is my script: (The PlayerGroundController script is just a script with a separate collider on my characters feet to see whether I should be able to jump or not)
public Rigidbody2D rb;
public float movementSpeed = 1f;
public float shootingDelay;
public float jumpHeight = 1f;
public Animator Animator;
bool canShoot;
bool jump;
public static float direction = 1f;
public float shootT;
public float prevY;
public float newY;
public bool isFalling;
public bool isJumping;
float isFallingToggleT;
float isJumpingToggleT;
void FixedUpdate()
{
if (jump == true)
{
rb.AddForce(new Vector2(0, Time.deltaTime * jumpHeight), ForceMode2D.Impulse);
jump = false;
}
}
void Update()
{
isFallingToggleT += Time.deltaTime;
isJumpingToggleT += Time.deltaTime;
shootT += Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space) && PlayerGroundController.canJump == true)
{
jump = true;
}
Animator.SetFloat("Speed", Mathf.Abs(Input.GetAxis("Horizontal")));
transform.position += new Vector3(Input.GetAxis("Horizontal") * Time.deltaTime * movementSpeed * 1.5f, 0, 0);
transform.localScale = new Vector3(direction * 0.2f, 0.2f, 1);
if (Input.GetKey("a") && Input.GetKey("d") == false)
{
direction = -1;
Animator.SetBool("isShooting", false);
Animator.Play("blend_tree");
}
if (Input.GetKey("d") && Input.GetKey("a") == false)
{
direction = 1;
Animator.SetBool("isShooting", false);
Animator.Play("blend_tree");
}
if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.15)
{
Animator.speed = 2.25f;
} else {
Animator.speed = 1f;
}
if (shootT > 1)
{
Animator.SetBool("isShooting", false);
Animator.Play("blend_tree");
}
if (Input.GetKey("j") && shootT > shootingDelay && Input.GetAxis("Horizontal") == 0 && PlayerGroundController.canJump == true)
{
Animator.SetBool("isShooting", true);
Animator.Play("player_shooting");
shootT = -0.25f;
canShoot = true;
if (shootT > shootingDelay + 0.1)
{
Animator.SetBool("isShooting", false);
}
}
if (shootT > 0 && canShoot == true)
{
GunScript.shoot = true;
canShoot = false;
}
newY = transform.position.y;
if (newY < prevY)
{
Animator.SetBool("isFalling", true);
isFalling = true;
isFallingToggleT = 0;
} else {
if (isFallingToggleT > 0.1)
{
isFalling = false;
Animator.SetBool("isFalling", false);
}
}
if (newY > prevY)
{
Animator.SetBool("isJumping", true);
isJumping = true;
isJumpingToggleT = 0;
} else {
if (isJumpingToggleT > 0.1)
{
isJumping = false;
Animator.SetBool("isJumping", false);
}
}
prevY = newY;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612214003im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2D Animation.Play does no effect 1 Answer
Blender 3d animation to Unity 2d animation 2 Answers
Import swf into unity 2d 4 Answers