- Home /
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.
Answer by Nazirzadeh · Feb 09, 2018 at 12:00 AM
Hi, First of all, FixedUpdate should be used instead of Update when dealing with Rigidbody.
Also you can simply freez it's position`transform.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.
the FixedUpdate informations is much appreciated, but I cant really use the constraint because I would like to be able to move on the y axis as well as all other axis. And as far as it behaving like it was in outer space that is kinda the idea.
that is exactly what I am looking for how would I go about zeroing out the speed of that object?
I am actually stupid your first comment actually works fine with what I am trying to do, for some reason I thought it would affect my movement script. but it does not so thank you very much for the response.