- Home /
Rigidbody and colliders, "weight" problem
Hello, I'll quickly describe my problem: the spaceship is a rigidbody in a box collider. When I apply a collider, the ship becomes "heavier" (I don't know if it's normal, but I accept it). I added a script that enable a "shield" around the ship when a key is pressed, so the ship doesn't receive damage when it is active. The shield has a collider, obviously, and it's instantiated as child of the "shield generator" (an empty object, child of the ship).
When I activate the shield, the ship gets heavier for the same reason written above, but the weird thing is that when the shield goes away (it lasts X seconds), the ship stays heavy. At first I tought the collider of the shield was still attached to my ship, but I tested it just colliding against an object and I'm sure there's no collider.. So, why my ship is still that heavy?
This problem is driving me crazy, I can't figure out how to fix it.
Thanks in advance ;)
Answer by sparkzbarca · Nov 06, 2012 at 11:30 PM
the collider is still attached unless you destroyed it after use and it should have existed before you pressed the shield button.
I'm not sure how your doing this collider generation but the way you should be doing it is disabling and enabling the collider.
Destroying and spawning the collider is more intensive. the collider should always be there and just be "on" or "off".
Once you have the colliders always there the weight will be constant, as expected and you can simply adjust your propulsion to look correct.
Here's my collider "creation":
I have a Shield prefab (not related to my ship.. it's a shield for every ship in the game). The Shield is a textured sphere with a sphere collider;
There's a "Ship Generator" object (an empty game object) as child in every ship, with a script attached (the script allows me -or the enemy- to instantiate the shield and automatically make it a child of the Shield Generator with the line clonedshield.transform.parent=transform);
When I press a key, I instantiate a copy of the shield (so the shield and its collider) around my ship. The ship gets heavier and it's quite normal (1 more collider attached);
The Shield has a timer: after 5 seconds it disappears (Destroy(clonedshield.gameObject, 5.0)). But here's the problem: after it goes off, the ship remains heavy! And I really don't know why. Correct me if I'm wrong: when you call the Destroy function, you destroy both the game object and its collider. So, why the ship remains heavy like there's the shield collider still attached?
well i'm still going with you shouldnt be starting out with the collider not on. and you shouldnt be destroying the collider.
START WITH THE shield on the ship it should always be on. but disable collisions. thats done with
gameobject.collider.enable = false; gameobject.renderer.enabled = false; //makes the object invisible
then after 5 seconds gameobject.collider.enable = true; gameobject.renderer.enabled = true;
i'm confused about this weight thing. the number of colliders has nothing to do with mass (as far as i know) only the number of rigidbodies. well I mean ideally you should only have 1 rigidbody with 1 mass.
does the Shield prefab include a rigidbody?
No, the Shield is just a sphere with a collider. No rigidbody. I don't know why the collider affects the handling of the ship, to be honest. I'm going to try your option now ;)
If someone knows why the collider acts like that..feel free to tell something :)
Answer by ProbePLayer · Oct 06, 2013 at 02:02 AM
I think I have a similar problem: I add a box as a child to this object with a rigidbody, and it suddenly shifts to the side where the box is, as if the center of mass has been changed. So maybe colliders don't have a mass, but they are included in how the center of mass is calculated. Right?
Your answer
![](https://koobas.hobune.stream/wayback/20220613083446im_/https://answers.unity.com/themes/thub/images/avi.jpg)