Player Stuck in Jump Animation

Hi, I am having trouble with my player stuck in jump animation in my game. I am using a tilemap with a
composite collider and set it to ground layer in layer masks. I can’t seem to figure it out. Any help greatly appreciated.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float moveSpeed;
    public float jumpSpeed;
    public Rigidbody2D myRigidbody;
    public Transform groundCheck;
    public float groundCheckDistance;
    public LayerMask whatIsGround;
    public bool isGrounded;

    private Animator myAnim;

    // Start is called before the first frame update
    void Start()
    {
        myRigidbody = GetComponent<Rigidbody2D>();
        myAnim = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckDistance, whatIsGround);

        if (Input.GetAxisRaw("Horizontal") > 0)
        {
            myRigidbody.velocity = new Vector2(moveSpeed, myRigidbody.velocity.y);
            transform.localScale = new Vector3(1f, 1f, 1f);
        }
        else if (Input.GetAxisRaw("Horizontal") < 0)
        {
            myRigidbody.velocity = new Vector2(-moveSpeed, myRigidbody.velocity.y);
            transform.localScale = new Vector3(-1f, 1f, 1f);
        }
        else
        {
            myRigidbody.velocity = new Vector2(0f, myRigidbody.velocity.y);
        }

        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpSpeed);
        }

        myAnim.SetFloat("Speed", Mathf.Abs(myRigidbody.velocity.x));
        myAnim.SetBool("Grounded", isGrounded);
    }
}

Sounds like you wrote a bug… and that means… time to start debugging!

Anything with Animations / Animators / Mechanim:

Only consider the code AFTER you have done this critical step:

Always start with the Animator state machine and prove it works in isolation, no code at all.

Here’s more reading:

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

If you get more insight and still cannot figure it out…

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you post code, only post the relevant code and always use the format button above.

Do not post photographs / screenshots of code.

Consider adding OnDrawGizmos/OnDrawGizmosSelected to your script and in that call Gizmos.DrawWireSphere or similar to draw out your Physics2D.OverlapCircle, that way you can more clearly see if that is where it’s supposed to be.

Make sure you’re using 2d physics components everywhere (they all are named with the 2d suffix). As far as I’m aware, they should never be mixed with physics components (those that don’t end with 2d)

Make sure the Ground animation is not a jump animation. And in the jump condition, call the jump animation.