- Home /
Children's position going haywire (Unity bug?)
In order to do a camera trick, I have a script on all my objects that creates a few clones of itself containing only a mesh and material a set distance away. These clones are attached as children to the main object- the thought is that with no scripts or ridgidbodies or anything like that on the clones, they will rely entirely on the parent / children relationship to keep in sync movement-wise. This works really well right up until the parent collides with the ground.
Upon hitting the ground, the parent object freezes it's position to make it "stick". This works fine for the parent, but the children all kinda freak out at this point. I've done some debugging on this, and it looks like the problem lies with my freeze only the position - the rotation remains unfrozen. As soon as I tell the script to freeze the parent's rotation as well upon landing, the children all land in the correct fashion.
Also, and the reason why I kinda think this might be a unity bug (even though I hate questions that use that), is that a the amount the children move from their proper spot seems to change from one run to the next, with no script changes. Seems like that shouldn't happen. Also also, the transform.position does not change- the numbers always look correct.
Here is a screenshot so you can see what I'm talking about. The first shot is the white child flying away from a launcher object, microseconds before impact. The white balls are tracers I added to show the flight path of the object. As you can see, it looks straight. The next slide to the right shows what happens a moment later when it lands and jumps to the right for some god-forsaken reason. Again, although the screenshot does not show it, the parent object lands correctly and does not 'jump'.
Anybody have a clue what is going on here?
Answer by Berenger · Feb 08, 2012 at 06:56 AM
Maybe it's related to the rotation. Just to be sure, change the mesh Sphere by any other mesh, tobe able to see when it rotate. When the localpos of a children isn't null and there is a rotation, the child will rotate around the parent, not it's own axes. So that might be your problem. Sorry if I what point out is a little obvious.
No, I think you're onto something here. When I pause it in debug mode and look at the parent, the rotation does have some small numbers in the values for some reason, usually in the thousandths or smaller. This is probably something I should have looked at first, but I expected the terrain to be flat... at least I'm guessing that's why my objects suddenly have really small rotations applied to them once they hit the ground.
So, from this, I presume I'm screwed? I basically have to freeze rotation if I don't want the children jumping about?
This still doesn't explain why the rotation values change from one run to the next, however. I'll just assume this is due to how Unity handles the heightmap or something.
Your answer
Follow this Question
Related Questions
Moving child transform also moves parent rigidbody 0 Answers
Network.Instantiate parenting on other clients 1 Answer
Why do Transform have hierarchies and not GameObjects? 2 Answers
Object changes position/rotation, when moved (in/out of parent) in the heirarchy in the editor! 0 Answers
Freezing Transforms 2 Answers