- Home /
Child Gameobjects are not fixed to the parent when using physics
I am trying to make a flight simulator-type game, but I am having problems with the child gameobjects of the rigidbody. At the top level I have the root gameobject which contains the model, the rigidbody, and the airplane script. Then, that game object has a bunch of empty gameobject children that I use to set the position to apply forces. Each one of those gameobjects has an airfoil script which applies it's own forces on the main rigidbody using AddForceAtPosition.
I have been having some problems, however, and after some debugging I found that the position of the empty gameobjects relative to the root are moving. The local position stays the same, but if I log the root transform.position - an empty gameobject position I have noticed that that fluctuates quite a lot. Shouldn't this stay constant?
Do you think this has anything to do with AddForceAtPosition?
yes they should be moving...
transform.position shouldn't be constant if its moving. if you move a parent EVERYCHILD moves with it...`LocalPosition` is the position offset from the parent while Position is global...that's why local position didn't change and transform.position
did.
And if your parent is moving, then so will be your child objects. why they do that is for practical reasons. e.g a player is carrying a gun, you add force to the player.. you want the gun to move with the player.
to fix your problem here's a hierarchy chart:
-RigiBody
-ContainerForEmpties
-Empty(s)
I know I expect them to be moving, but they move incorrectly relative to each other. What I said was the difference between the global positions isn't constant. I ended up lowing the timestep and that fixed the problem for the most part. It seems like because the empty gameobjects that had the airfoil code were taking more time to do calculations they were a step or two behind everything else. This is why when the velocity was large they didn't move exactly with the parent.
Ok, Now I understand, sorry for that. I was confused since you said
The local position stays the same
and then
log the root transform.position
Anyway back to the problem heres something on Airfoils for your physics. http://en.wikipedia.org/wiki/Airfoil
and AddForceAtPosition
Could Be it http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForceAtPosition.html
I'm not sure if that's the right approach or not
Your answer
Follow this Question
Related Questions
Child rigidbody acting strange when moving parent. 0 Answers
" You should never have a parent and child rigidbody together " ? 2 Answers
Is it possible to prevent parent rigidbody physics from effecting children rigidbodies? 1 Answer
Make a simple tree 1 Answer
Child rigidbody clipping through walls. 2 Answers