Before updating to Windows 10 you may need to return your Pro license. More information here

hit.rigidbody.useGravity problem?

Hi, I have a small snippet of script here :

 var colliders : Collider[] = Physics.OverlapSphere (explosionPosition, radius);

 for (var hit : Collider in colliders) {
     if (hit.rigidbody)
         hit.rigidbody.useGravity = false;

The script works fine if there are only rigidbodies in the overlapsphere, disabling all gravity of the rigidbodies. But, when there are objects that don't have rigidbodies attatched to them in the sphere the other rigidbody in the sphere wont respond to the script ( eg: there are 2 rigidbody and 1 normal game object in the sphere, the rigidbody wont react to the script because there is another gameobject with no rigidbody in the sphere ). It simply returns a MissingComponentExeption "There is no 'Rigidbody' attached to the "BLABLA" game object, but a script is trying to access it." Searched around the forums, no luck, so I decided to post another question here. Please help in JS, thanks!

more ▼

asked May 31, 2011 at 05:34 AM

avatar image

97 41 32 36

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

You can add:

 var otherObj : GameObject = hit.collider.gameObject;
     hit.rigidbody.useGravity = false;

Otherwise it will try to apply to something that doesn't exist.

more ▼

answered May 31, 2011 at 09:18 AM

avatar image

10.1k 61 75 105

Thanks for saving my life again dude!

May 31, 2011 at 09:44 AM eric_c

If I knew your life was on the line I would've answered earlier. :)

May 31, 2011 at 09:46 AM save
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: May 31, 2011 at 05:34 AM

Seen: 1994 times

Last Updated: May 31, 2011 at 09:46 AM