- Home /
Rigidbody not responding to setting gravity, but setting in inspector works.
I'll try to keep this as short and simple as possible.
I have an item which spawns, floats up a few units, and then is supposed to drop and move either left or right and bounce of walls. The item has a rigidbody, and when it's floating, I deactivate gravity for the rigidbody so it is able to 'float'. Turning the gravity back on does not work, however, and the item remains floating. If I set the rigidbody's gravity on in the inspector while the game is running, it works fine.
Current code: http://pastebin.com/NxNuHCrt
I am spawning an item with the SpawnItemAndFloat function, which deactivates gravity, floats the item, and should reactivate it. It never reactivates the gravity, though debugging if the item has gravity says it does, when it clearly doesn't. Not sure if this is a bug or I'm just doing something wrong.
Answer by HarshadK · Oct 21, 2014 at 01:19 PM
Call Rigidbody.WakeUp on your rigidbody after you set the gravity to true.
// if item has a rigidbody
if(item.rigidbody != null)
{
// turn gravity back on
item.rigidbody.useGravity = true;
item.rigidbody.WakeUp();
}