I really need help with 2d jump animations!!!

I am making a 2d platformer and have managed to get him running left and right and jumping. My animations for idle, running left and running right work fine (mostly) but I am having real trouble with the jumping side of things as my character is not symmetrical and I need different animations for left and right for each different action.
I have tried to manually add the input within the code in various different ways and have also tried to use a lot of different video tutorials and have come up against a wall.
Any advice that can be offered would be greatly received as I have spent the last 2 weeks on the movement and I really don’t want to get stumped for another 2 weeks!!
I have included the code I have so far below.

Thanks in advance!!

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

public class NewPlayControl : MonoBehaviour
{
    public float movespeed;
    public float jumpheight;
    public Rigidbody2D rb;
    public Animator anim;
    public bool grounded;
    public Transform groundcheck;
    float groundradius = 0.2f;
    public LayerMask whatisGround;


    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        anim = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (grounded && Input.GetKeyDown(KeyCode.Space))
        {
            rb.velocity = new Vector2(rb.velocity.x, jumpheight);
        }
        if (grounded && Input.GetKey(KeyCode.LeftArrow) && Input.GetKeyDown(KeyCode.Space))
        {
            anim.SetTrigger("JumpLeft");
            anim.Play("JumpLeft");
        }
    }

    

    void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            rb.velocity = new Vector2(-movespeed, rb.velocity.y);
            anim.SetBool("IsRunningLeft", true);
            anim.Play("RunLeft");
        }
        else if(Input.GetKeyUp(KeyCode.LeftArrow))
        {
            anim.SetBool("IsRunningLeft", false);
            
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            rb.velocity = new Vector2(movespeed, rb.velocity.y);
            anim.SetBool("IsRunningRight", true);
            anim.Play("Run");
        }
        else if (Input.GetKeyUp(KeyCode.RightArrow))
        {
            anim.SetBool("IsRunningRight", false);
        }

        grounded = Physics2D.OverlapCircle(groundcheck.position, groundradius, whatisGround);
    }
}

Your animator looks pretty weird tbh xD You didn’t put any transition from Idle to RunLeft so there’s not going to be any animation playing when you quit the idle state. It’s only when the IsRunningLeft toggle will be false that it will go back to Idle and play the transition animation.

I suggest you put a transition from Idle to RunLeft with the condition of IsRunningLeft is true so when you’re pressing the left arrow it will play your running left animation. The returning condition should be if IsRunningLeft is false.

Concerning the jump I think you wrote too much useless code that makes it more complicated.

You should only have a condition check for when you’re pressing the left or right arrow :

 if (grounded && Input.GetKey(KeyCode.LeftArrow)){
                 rb.velocity = new Vector2(-movespeed, rb.velocity.y);
                 anim.SetBool("IsRunningLeft", true);
             }
 else if(Input.GetKeyUp(KeyCode.LeftArrow))
             {
                 anim.SetBool("IsRunningLeft", false);
             }


 if (grounded && Input.GetKey(KeyCode.RightArrow)) {
                 rb.velocity = new Vector2(movespeed, rb.velocity.y);
                anim.SetBool("IsRunningRight", true);
             }
             else if(Input.GetKeyUp(KeyCode.RightArrow))
             {
                 anim.SetBool("IsRunningRight", false);
             }

and if you’re pressing space :

if(grounded && Input.GetKey(KeyCode.Jump)){
         anim.SetBool("IsJumping", true);
}

You need to add the IsJumping bool in the animator.

When you got this done you should make the transitions in the Animator:

Left side

Idle → RunLeft : IsRunningLeft is true

RunLeft → Idle : IsRunningLeft is false

RunLeft → JumpLeft : IsJumping is true

JumpLeft → RunLeft : IsJumping is false and IsRunningLeft is true

JumpLeft ->Idle : IsJumping is false

Right side

Idle → RunRight : IsRunningRight is true

RunRight → Idle : IsRunningRight is false

RunRight → JumpRight : IsJumping is true

JumpRight → RunRight : Is Jumping is false and IsRunningRight is true

JumpRight → Idle : Is Jumping is false

Okay that’s it I hope it will work as you wish because I can’t really try it myself right now and see if it works properly. Try it out and tell me if it’s working or if there’s any problem you’re encountering :slight_smile: