- Home /
How to get child object on top of his parent.
Hello.
I have a little problem with position of my child object. I will try to explain it on example.
I want to merge two objects into one (when they collide one of them became child of main object). So if they collide from top side this child object should be postion on top of the parent postion. But now it looks like on the 2nd picture. My code so far:
childObject.transform.SetParent (parentObject.transform);
childObject.transform.position = parentObject.transform.position;
I tried to get height of parent object and set that postion but I think I do it wrong :/ So can anyone help me how to get that?
Answer by OsmiousH · Aug 22, 2016 at 10:22 PM
I dont want to seem rude but your doing it all wrong
your script sets position
but there are other things that needs changing
Like,
The rotation (in Quaternion format)
The Scale
Etc.
childObject.transform.SetParent (parentObject.transform);
childObject.transform = parentObject.transform;
Your answer
![](https://koobas.hobune.stream/wayback/20220612091346im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I get the global position 2 Answers
Parent transform not following child transform 0 Answers
Where to find original unity Parent/Child script? 2 Answers
Position as a child 1 Answer
Making child rotation/position independent of that of parents' 1 Answer