ridgidbody child ignoring parents movment

today while playing with unity i learned that if you parent an object with a rigid-body to another object, that it wont move with it, it will rotate with it, but not move with it

is there any particular reason for this??

The parent moves the child’s transform but the child doesn’t want to be moved because it is controlled by the physics engine and it knows it shouldn’t.

I think generally it is a good idea to not mix transforms that move without physics and transforms that move with physics together unless the non physical transforms are just children of the rigidbody and don’t interact much.

oh i see

thanks

okay well since i cant parent rigid bodys and have them move with other things, how could i get one to follow my char as if it were parented??

it seems like a strange limitation, mostly because the child object will still orbit around its parent when it turns, but not when it moves

how can i get around this??

If you want it to move 100% in lock step with the parent, just remove the rigidbody from the child object

oooh okay

im using a raycast to select the object to child to my char, how can i get into the object i have hit and turn off its rigid body component??

The hit returned from raycast contains a reference to the collider it hit, which is still attached to the child object.

edit woops… sorry misunderstood your question. You simply remove the rigidbody by calling Destroy on it:

// code after a successful Raycast.
var go = hit.collider.gameObject;
go.transform.parent=newParent;
if (go.rigidbody) // Remove the rigidbody if present
   Destroy(go.rigidbody);