- Home /
How to conect rigidbodies, and then disconnect them when desired
Hi
When one needs to connect two (or more!) rigidbodies together, and then when needed, "let go" of objects on command, what are the necessary steps? (imagine a fighter aircraft dropping empty fuel tanks...)
It seems to me that there are various things that need to be considered:
-How to connect them to begin with?
-What physics properties must the objects share? (simply both being rigid bodies?)
-When/how to turn on the physics of the object to be released?
Thank you!
Answer by Ryder · Jun 14, 2010 at 05:01 AM
The answer has, as suspected, a few parts.
First, rigidbodies will not normally stay together as the physics engine will act on them independently. To overcome this, on the child rigidbody, select "is Kinematic" in the inspector for the child.
When the appropriate time for release comes, set the isKinematic property to false:
rigidbody.isKinematic = false;
Next, to fall off naturally, one has to put the translational and rotational velocities into the child object so that it falls away naturally:
rigidbody.velocity = transform.parent.rigidbody.velocity;
angularVelocity = transform.parent.rigidbody.angularVelocity;
When all of that is complete, the child object can be severed from the parent with:
transform.parent = null;
Answer by qJake · Jun 14, 2010 at 01:16 AM
If you just want one object to follow another one, you don't even have to mess with the Rigidbodies (nor are they required), you can just set the parent of one to be the other. So in your example, you would set the parent of the fuel tank(s) to be the aircraft, and then when you want them to "drop", simply remove the parent-relationship, and the fuel tanks will no longer be "attached" to the plane, and thus, they'll fall.
See the Transform.parent reference for scripting examples on how to parent and de-parent objects. If you want to parent something in the Editor, simply drag an object onto another one in the Hierarchy.
If this isn't what you were looking for, post a comment (not a new answer), and I'll revise my post to help you as best I can.
Rigid bodies parented to other rigid bodies don't seem to go together. Their independent physics causes them to go wherever!
Please keep in $$anonymous$$d the title of the question, and the first sentence which both specify that we are dealing with rigidbodies very specifically.
$$anonymous$$y guess is that the rigidbody component of the dropped object will have to somehow be disabled (or non-existant) until the time comes for it to fall away.
Another guess is that it will need to assume the movement and rotation vectors of the parent at the same time.
I think we have a bit to go before we arrive at an answer.
Well, you could always disable the gravity or the rigidbody entirely (if you don't need physics). Just set rigidbody.gravity = true or false, or set rigidbody.enabled = true or false.
@ Spike... in the case of gravity, what that would do is simply leave, for a rigidbody, to simply sit in place, see$$anonymous$$gly un$$anonymous$$thered to the parent... not falling, but never the less, effectivly disconnected from the parent (as physics, sans gravity) is still in full effect.
For the example of the fuel tank being dropped, it must of course respond to gravity (and be tied to the aircraft before hand)
And I believe that rigidbody.enabled is an invalid parameter/argument.
I did my own quick test, and it seems that if the rigidbody is sleeping (isAwake = false), then it will follow its transform parent around, otherwise not. It's kinda dumb, but I guess I see why that is.
Answer by richardgengle · Aug 10, 2020 at 09:42 AM
is kinematic looks good, but what if u want to attach a propeller to an airplane?