Why does my character get stuck in my jump-animation?,How to fix my double Jump Bug?
My problem: Sometimes my character get stuck in the Jump-Animation randomly when I jump and fall on the ground again. It often occur when falling from high distances.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController2D controller;
public Animator animator;
public float runSpeed = 40f;
float horizontalMove = 0f;
int Jump_Counter = 0;
bool jump = false;
bool crouch = false;
// Update is called once per frame
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
animator.SetFloat("Player_Speed", Mathf.Abs(horizontalMove));
if (Input.GetButtonDown("Jump") && Jump_Counter == 0)
{
jump = true;
animator.SetBool("IsJumping", true);
Jump_Counter += 1;
}
if (Input.GetButtonDown("Crouch"))
{
crouch = true;
}
else if (Input.GetButtonUp("Crouch"))
{
crouch = false;
}
}
public void OnLanding ()
{
if (Jump_Counter >= 1)
{
animator.SetBool("IsJumping", false);
jump = false;
Jump_Counter = 0;
}
}
public void OnCrouching (bool isCrouching)
{
animator.SetBool("IsCrouching", isCrouching);
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Coins"))
{
Destroy(other.gameObject);
}
if (other.gameObject.CompareTag("Hearts"))
{
Destroy(other.gameObject);
}
}
void FixedUpdate()
{
// Move our character
controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612220911im_/https://answers.unity.com/themes/thub/images/avi.jpg)