Jump animation won't flip mid-air

I’ve been trying to get my animations to work, and they are, except there’s one issue: the jump animation won’t flip (along the X axis) whilst mid-air. If you land and jump again and you change the direction, it flips, but not during the jump. (All my other animations are working fine and flip when required). Here’s my code:

using UnityEngine;

public class CharacterMovement : MonoBehaviour
{

public float moveSpeed = 1;
public float jumpForce = 1;
private Rigidbody2D rgbd;
private Animator anim;
private SpriteRenderer sr;
private void Start()
{
    rgbd = GetComponent<Rigidbody2D>();
    anim = gameObject.GetComponent<Animator>();
    sr = GetComponent<SpriteRenderer>();
}

private void Update()
{
    var movement = Input.GetAxis("Horizontal");
    transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * moveSpeed;

    if (movement > 0 && Mathf.Abs(rgbd.velocity.y) < 0.001f)
    {
        anim.Play("Run");
        sr.flipX = false;
    }
    
    else if (movement < 0 && Mathf.Abs(rgbd.velocity.y) < 0.001f)
    {
        anim.Play("Run");
        sr.flipX = true;
    }
    
    else if (movement == 0 && Mathf.Abs(rgbd.velocity.y) < 0.001f)
    {
        anim.Play("Idle");
    }

    if (Input.GetButtonDown("Jump") && Mathf.Abs(rgbd.velocity.y) < 0.001f)
    {
        rgbd.AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse);
        anim.Play("Jump");
    }

    if (Input.GetButtonDown("Jump") && Mathf.Abs(rgbd.velocity.y) < 0.001f)
    {
        rgbd.AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse);
        anim.Play("Jump");
    }
}

}

I’m a beginner, so I would appreciate if someone could help!

if (movement > 0 && Mathf.Abs(rgbd.velocity.y) < 0.001f)
{
anim.Play(“Run”);
sr.flipX = false;
}

Here you are limiting this loop only to when there is no velocity on the y axis, which means if your y velocity is greater than 0.001f you cant flip.

Instead you could.

if (movement > 0)
     {
         if (Mathf.Abs(rgbd.velocity.y) < 0.001f)
         {
              anim.Play("Run");    
         }
         sr.flipX = false;
     }

But I would suggest rather using a collision check to see if touching the ground, this has just worked more dynamically for me.

Hey there! Thanks a lot, it worked, I didn’t realise the fix was so simple! I’m not too familiar with the collision check, however, I’ll look into it and see what I can find. Thanks again!