I have a Rigidbody on a spaceship. The spaceship has mountpoints which are parented to the main ship. During runtime I want to mount a weapon to those mountpoints, the weapon is a prefab with a box collider.
The mounting process works fine and the weapon is collidable, however it seems the rigidbody is not being set to the collider.attachedRigidBody, and the collider remains a static collider (i.e nothing exerts force on it except its parent).
So the basic effect is, if you run the weapon into something physics goes to hell and no torque or force is sent back to the parent object (the ship). Where if the ship is struck, the physics still work properly.
Is there any way to add a child collider to a rigidbody at runtime?
*Further info Here is a sample of the code:
*Further update: Now I have found a workaround for the problem. If I parent the weapon to the shipMount and then add a bounding box to the weapon, it works fine. Like so:
I also had a problem with .attachedRigidbody property not being updated after chaging parent at run-time, but just discorevered when you disactivate and activate the game object with the problematic collider - everything is as it should be in the first place!
Try this one :
answered Sep 01 '10 at 12:20 PM