- Home /
child not moving with parent
very basic here: i want to be able to instantiate cubes as childs of my gameObj and move them toghether. this is just testcode: i want to instantiate a cube object and then apply a force to my current object. the cube should follow, right? no, it doesnt. (gravity is off)
public Transform cube; Transform newCube; Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody>();
newCube = (Transform)Instantiate(cube, transform.position + Vector3.left, transform.rotation);
newCube.parent = transform;
}
void FixedUpdate()
{
rb.AddForce(Vector3.forward);
}
Does your prefab have it's static flag set? As if so this will prevent it's position from updating.
Answer by Garazbolg · Oct 13, 2015 at 01:34 PM
I tried your code and it works fine with me.
The Cube you're trying to instantiate does it also have a rigidbody ? because that would make him not follow.
If not what kind of component do you have on your cube ? For my part i only have Collider, MeshRenderer and Mesh Filter and it works fine.
i got rigidbody on both. the child actually moves very slowly due to attrition i guess (is that even a thing?), and if i try to move them manually pausing playmode they move as expected...
i removed the rigidbody and it works now, thanks.
i dont really get it, tho. now i cant apply forces to the child, right? would i be able to if i used a fixedjoint ins$$anonymous$$d?
The thing is that rigidbody move in World space no matter if they are the child of a moving gameObject.
But fixedjoint should do the trick (didn't used them much).
Answer by gersonbellodegoes · Dec 02, 2020 at 12:36 AM
You can check "IsKinematic" when they are together, this will make them follow
Answer by taimur_azhar · Jan 20, 2018 at 12:44 PM
I got it fixed as I made freeze position constraints checked.
Answer by dongminghui1313 · Aug 16, 2021 at 08:34 AM
It's an old question but I will just leave the answer here. For me, the child was set to static by accident. Double-check you didn't turn it on.
Your answer
![](https://koobas.hobune.stream/wayback/20220612041119im_/https://answers.unity.com/themes/thub/images/avi.jpg)