How to fix initial gravity problem?

this works for the most part, like once i get up to 80 on the y axis my gravity shuts off but there is like an persistent gravity on the rigid body that stays until there is a collision with the ground. and only after that first collision with the ground plane will the gravity be turned off the way I would like it to.

public Rigidbody asteroid;
public Rigidbody player;

void Update () {
    
    if (transform.position.y > 80)
    {
        GetComponent<Rigidbody>().useGravity = false;

    }
 }

the asteroids stay up in the air like they are supposed to.

any help with this would be much appreciated.

thanks in advanced.

Hi, First of all, FixedUpdate should be used instead of Update when dealing with Rigidbody.

Also you can simply freez it’s positiontransform.rigidbody.constraints = RigidbodyConstraints.FreezePositionY;

Keep in mind,if you set the useGravity to false the rigidbody will behave as in outer space. If an objects enters to a 0 gravity space, it continuous movement based on his last speed. You need to take care of its speed too.