- Home /
How to use Hinge Joints correctly inside a parent?
I'm trying to create a cube with two 'legs' using hinge joints so they move like spaghetti using the physics engine :D
The issue I'm having is that when I have created a 'leg' and I want to join it on to my cube that works oky but when the cube and the 'leg' are inside a parent and I move the parent the movement doesn't affect the physics anymore.
My parent hierarchy is like this:
Character
Head (Another mesh)
Body (Another mesh)
- Cube
- Leg1
Anchor
Joint1
Joint2
Joint3
Joint4
- Leg2
Anchor
Joint1
Joint2
Joint3
Joint4
- Leg1
Now I want to have Character as a prefab, and when character moves the physics of that movement affect the joins but it doesn't.
Any idea how to fix this issue? thanks!
Answer by Owen-Reynolds · Oct 24, 2013 at 03:56 PM
Don't use parenting.
Moving the parent also moves the child legs. It moves them first, "by magic." Then the physics step sees the leg is perfectly under the body, so has no reason to do anything.
But without parenting I can't make a prefab out of it can I?
I'd parent everything and on Start() detach children something among those lines
You could try making an object and then parent everything separately under the object so that ins$$anonymous$$d of the cube being the parent that dictate the position, it will be a "sibling" under the prefab. That way you don't have to write any scrip.
As per Sakka's comment (all children of fake empty parent) it would be easy code, just after the Instantiate:
foreach(Transform tran in thingIJust$$anonymous$$ade) tran.parent=null;
then Destroy( thingIJust$$anonymous$$ade );
If you need a pointer to the "parent" cube (now not really a parent,) start out with Transform cube = thingIJust$$anonymous$$ade.Find("cube"));
Your answer
![](https://koobas.hobune.stream/wayback/20220613120538im_/https://answers.unity.com/themes/thub/images/avi.jpg)