- Home /
How to reset the Gravity of an object from script
Hello All, i have a sprite sheet and i have split it by using sprite editor. And now i have dragged the a single frame of sprite sheet into the scene.And i attached a Rigidbody2d physics component(P.S i am in 2d view)now my gravity is enabled and i have also added a java script file to this frame .What i want is when i click on screen the gravity of object should reset to zero. So how this could be done.
"Gravity" is a global physics constant, it's not per object.
If you mean reseting the position of your object you should save the wanted position to a variable and set your objects position to that variable on click. If you mean freezing the object in place set its gravityScale to zero
Answer by musaranya · Apr 09, 2014 at 08:50 AM
Maybe something like this will work:
referenceToYourObject.rigidbody2D.gravityScale=0f;
Wherever you handle the click on the screen event you can reference to the rigidbody of your object and set its property gravityScale to zero (I think this is the alternative to the Rigidbody.useGravity when working in 2D). I haven't tested it but according to the documentation it should work :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613142310im_/https://answers.unity.com/themes/thub/images/avi.jpg)