- Home /
rigidbody.useGravity doesnt work?
I have a problem here. I made a balloon that is affected by gravity, I want it to go straight up when I hold the up arrow key, therefore, I need to turn off the gravity when the key is pressed, or else, the balloon will lose speed and fall down. The thing is: when I type "rigidbody." or "rigidbody2d.", useGravity doesn't appear. What's happening?
what do you mean by "when I type "rigidbody." or "rigidbody2d.", useGravity doesn't appear."?
in your script editor? which is? ... a bit more information might help us help you
and if intellisense doesn't show it, what's stopping you typing it? ;)
Yes, in the script editor, Visual Studio 2015. Not only useGravity, but also other stuff like "OnCollisionEnter2D".
I'm guessing you might need to use GetComponent<Rigidbody>().useGravity = true;
ins$$anonymous$$d.
Hi @Shenic ,
I think that you need to access the rigidbody of the gameobject. For that,
If rigidbody is 2d -
gameObject.GetComponent ().gravityScale = value ;
where the value can be a float value. For 2d rigidbody we are giving the gravity scale value, not the Boolean whether to use gravity or not.
if rigidbody is 3d -
gameObject.GetComponent().useGravity = true ;
Hope this will help you.. Happy coding.
Your answer
Follow this Question
Related Questions
Instantiated prefab changes gravitational speed when dragged? 0 Answers
2D character movement is jittery (top-down) 1 Answer
Trying to reverse planetary gravity 1 Answer
rigidbody.Use gravity not working from script 0 Answers
jump script : 2D 1 Answer