# Zero Gravity like Physics?

Hi,
I need to find a way so that once a certain key is pressed, there is no gravity in the space around me. I am creating a 2D game which does not use Unity’s built in gravity, instead I have this piece of code in the update function of each of my objects:

``````if (gravityType == "up") {
} else if (gravityType == "down") {
} else if (gravityType == "null") {
// ===== What goes here? =====
}
``````

This just means a negative force of 9.8 units per second will be applied on the Y axis to the object it is applied to. I want to find a way how there is no gravity in the scene, so obviously I will have to stop applying this force, so that things seem to bounce of surfaces and maintain there current velocity over longer distances. If anybody knows how to do this it would be much appreciated if you could let me know.

Many Thanks,

Tommy Eaves

You can simply replace the 9.8f by a variable, and set that variable to zero when the key is held down.
So you could change your code to:

``````if (gravityType == "up") {
myGravity = 9.8f;
} else if (gravityType == "down") {
myGravity = 9.8f;
} else if (gravityType == "null") {
myGravity = 0f;
}
``````if (Input.GetKey())
``````if (Input.GetKeyDown())