- Home /
Child object not moving with parent.
I have a gameObject with a rigidBody2D attached to it which moves at a certain velocity but when I instantiate a gameObject as a child to that object it doesn't move with the parent. Why?
Are you moving child object with rigidbody or parent? you have not given a proper answer of the question asked by @Addyarb, your answer is still confusing.
The child object doesn't have a rigidBody2d attach and even when I do add one it still doesn't move with the parent, just stays at the same position it was intantiated at even though the parent is moving.
Answer by smallbit · Jul 20, 2014 at 09:00 AM
Can you post screenshot of your hierarchy after instantiating? are you sure you set the parent of instantiated object via code? Does your child object have any script component that modify its transform.position?
Thanks! Your question fixed my problem. Problem was that i had a rigidBody2d attached which moved it along with a script, once i removed them both it started working!
Another thing is that i couldve just made the child's rigidBody2d kinematic... silly me.
Answer by Antares_Insomnious · Feb 26, 2017 at 12:55 PM
This is really late, but maybe it will help someone else who finds this. this is what I did. *NOTE: When you set the new Vector3, you'll need to use some sort of offset. I used my transform.position.y + 0.25... but that is just to get the object directly above my parent object. I hope this helps someone.
[SerializedField]
GameObject gObject;
void Start {
GameObject go = Instantiate(gObject, new Vector3(0f, 0f, 0f), Quaternion.identity) as GameObject;
go.transform.parent = this.transform;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613154434im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
More realistic physics on child collisions 2D 0 Answers
How to create a variable jump height 2 Answers