[Noob] Animation issue with float - Y-axis doesn't update,[Noob] y axis doesn't update, help!

Hi All,

I am trying to switch between run animation and jump animation when y=0.

So…

When y>0, Run->Jump animation
and when y<0, Jump → Run animation.

However, the animator parameter lags and does not update the y-axis, and gets stuck at positive value when the actual y-axis of the sprite on Inspector is a negative value. This happens especially when the sprite is dropped from high to low.

Could someone please tell me why this is happening, and what are the fixes?
I am a complete noob and have no idea why this is happening

Thank you in advance! (ㅠㅁㅠ)/

using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;

public class DragonMove : MonoBehaviour
{
public float dragonJump;
private Rigidbody2D myRigidbody;
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()
{
    foreach (Touch touch in Input.touches)
    {
        if (touch.phase == TouchPhase.Ended)
        {
            myRigidbody.AddForce(transform.up * dragonJump);
        }
      
        myAnim.SetFloat("vFly", myRigidbody.position.y);
        
    }
}

}

,Hi All,

I am trying to get my character to change animation at y=0 using float,

However, there is a lag and the y axis on the parameter gets stuck at positive number when the actual y is less than 0, and the animation does not react until there is another controller input to move the object

Could somebody please tell me how to fix this?

using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;

public class DragonMove : MonoBehaviour
{
public float dragonJump;
private Rigidbody2D myRigidbody;
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()
{
    foreach (Touch touch in Input.touches)
    {
        if (touch.phase == TouchPhase.Ended)
        {
            myRigidbody.AddForce(transform.up * dragonJump);
        }
      
        myAnim.SetFloat("vFly", myRigidbody.position.y);
        
    }
}

}

Have you checked myRigidbody.position.y value at runtime, try print(myRigidbody.position.y). I think what you see in the inspector is transform.position or transform.localPosition, and those are not always the same.