- Home /
gravity script
i have a gravity script that i attach to a rigidbody but for some reason it doesn't work and suggestions?
function OnTriggerEnter (other : Collider) {
if (other.attachedRigidbody) {
other.attachedRigidbody.useGravity = false;
}
}
collider.isTrigger = true;
This question doesn't provide enough information to provide an answer. Why does it not work? what do you expect to happen, but is not happening? Please read Unity Answer's Advice to New Users and FAQ, to learn how to help us help you.
i was expecting the item to be effected by gravity and fall to the ground and bounce around or something but for some reason nothing happens the item just floats in mid air.
Answer by robertbu · Jul 27, 2013 at 09:15 PM
The game object that has 'other' must have a Rigidbody
The Rigidbody on other must not be kinematic (IsKinematic flag should be off).
Make sure 'other' is the game object you expect by doing Debug.Log(other.name).
It is possible the rigidbody is sleeping. Add this line to your code below line 3:
other.attachedRigidbody.WakeUp();