- Home /
how to Apply Gravity at Run time ..?????????
Hello Frends........ I m developing a game in my game when i click on mouse button then apply Gravity to particular object...
please a give me some idea.............
Thanks a lot.
Answer by aldonaletto · Oct 01, 2011 at 03:44 PM
It depends on what are your objects, and what are you trying to do. If the objects are rigidbodies, and you intend to use the standard gravity (Physics.gravity), you can just set rigidbody.useGravity to true/false when needed. On the other hand, if you need a different gravity orientation or value, let useGravity = false and apply a force at FixedUpdate when enabled by the click:
var localGravity: Vector3 = 9.8 * Vector3.up; // inverted gravity var gravityOn: boolean = false;
function OnMouseDown(){ gravityOn = !gravityOn; // toggle the gravity when clicked }
function FixedUpdate(){ if (gravityOn) rigidbody.AddForce(localGravity); }
Thanks a lot for help aldonaletto once again thanks........
@Lavpatel
If it did work, you should accept the answer as working. That will make it easier for people to get the correct/working answer for this question, if they get the same problem!
/TheDDestroyer12
Answer by Vetpetmon · Dec 01, 2014 at 11:40 PM
You need to attach a rigidbody. Make sure it has gravity enabled.