- Home /
" You should never have a parent and child rigidbody together " ?
I found this tip in http://unity3d.com/support/documentation/Manual/Physics.html But I would like to know why? What sort of problems can this create?
Answer by Bunny83 · May 04, 2011 at 11:55 AM
A rigidbody component controls the GameObject it's attached to. The velocity get's calculated in worldspace. If you parent a rigidbody to another, the child will get additional "forces" (actually the gameobject will move along with the parent, so no real forces) that will make the child do crazy things. A rigidbody represents one single physic object. Parent-child relationship doesn't work here. If you want two rigidbodies to be bound together, use joints.
Which joint does the same as Parent-Child? I want want an object to have the same movement as another object.
Are you sure that you need the secondobject to be a seperate rigidbody? If you parent an object (without a rigidbody) to another it will be part of the rigidbody of the parent. Anyway the FixedJoint is what you want: http://unity3d.com/support/documentation/Components/class-FixedJoint.html
I have 3 objects. Object A is the movable object for the player. Object B has a Fixed Joint with Object A. Object C is an item the player has to pick up. When you pick Object C, it becomes a child of Object B. I now kill the rigidbody of Object C before make it Child of Object B. But now, Object C scales and rotates when it is pick up or dropped down. Do you know a solution?
Answer by kubajs · Mar 07, 2017 at 12:36 AM
I don't think this is valid anymore. According to official Unity documentation (https://docs.unity3d.com/Manual/class-Rigidbody.html) "Parenting When an object is under physics control, it moves semi-independently of the way its transform parents move. If you move any parents, they will pull the Rigidbody child along with them. However, the Rigidbodies will still fall down due to gravity and react to collision events."
Actually this was only method which properly worked for me when trying interaction of player with platform. No jittering, no issues.
My case: Parent player with non kinematic rigidbody to platform on collision (OnCollisionEnter), unparent on CollisionExit. Setting rigidbody to isKinematic doesn't help much here as you would need much more sophisticated way to set proper position of player on the platform etc. You cannot just switch rigidbody to isKinematic on collision otherwise player might easily stay with half of his body under the platform or be affected with a similar undesired effect ;) Using rigidbody with physics eliminates this problem as player is either knocked back when jumps to the side of the platform instead of it's top and is not parented at all or doesn't miss the platform and is parented immediately.
I haven't had any problems when parenting non kinematic rigidbody. The movement was pretty smooth. In all the other cases the player was affected by terrible jittering.
Im so glad you replied to this Im having to do a similar thing, but I don't really understand rigid bodies completely yet so I found this and almost thought I broke unity in a weirdly specific way.
Thankyou for the answer! FYI, I am researching a problem which I think is caused due to parenting Rigidbodies, in 2018.
$$anonymous$$y Case: A chain of Hingejoints works ok when at the top level, but when underneath a FreePosition Rigidbody which is scaled in one axis, the children stretch in and out along that same axis, like they are made of jelly. Everything non-kinamatic, children using gravity.
So I think that the OPs tip is still valid in certain edge cases? Either way hope that is helpful to future readers deciding wether to use parenting or not: Watch out for scaling of the parent affecting the children when you test.
Hi @kubajs, I realize this is already a year old reply, but as I'm struggling with this exact problem right now and you seem to be the only person having figured it out on the whole internet, I thought I'd give it a shot to ask you for some details.
I'm trying to do pretty much what you described here. I have a top-down game where my Player is controlled with a dynamic Rigidbody2D and want him to be able to move along with a moving platform, while still being able to control him normally.
Now, the only way I can get it to semi-work are either: - setting the players Rigidbody2D to kinematic on Trigger with the platform. This however completely messes up the way my player controls while on the platform - moving the Platform not with a Rigidbody2D, but by manipulating it's transform directly. This works a little better, but the the player moves along jittery, and the controls are messed up by it a little as well (not as bad as the kinematic-option mentionned before).
I was just wondering if you could share some more detail, what exact properties/methods are you using in this scenario? Are you moving your platform with a rigidbody or with transform?
Sorry for bombarding you with this, but I'd love to hear from you. :)
Your answer
Follow this Question
Related Questions
Child rigidbody clipping through walls. 2 Answers
Child rigidbody acting strange when moving parent. 0 Answers
Make a simple tree 1 Answer
Is it possible to prevent parent rigidbody physics from effecting children rigidbodies? 1 Answer
Child Gameobjects are not fixed to the parent when using physics 0 Answers