- Home /
Children rotating constantly are moving parent with Rigidbody?!
http://answers.unity3d.com/questions/1264898/children-with-lookat-in-update-moves-root-object.html
Related to an older question I posted that I haven't found any answer to...
It seems that having children that are constantly changing their rotation, even if it's a very small change, will move the root object if it has a Rigidbody that is not kinematic or is not affected by gravity.
Making the rigidbody kinematic stops this, stopping the rotation of the children stops this, removing the rigidbody stops this. Any ideas? Thanks!
Two factors that affect the speed of the Rigidbody movement:
1) Child rotation speed
2) Child distance from the origin
3) The number of children rotating constantly
In a test I made, I had a child spinning 3-4 times / second, and i got it to move a lot just by placing it like 100 units away.
I can't reproduce this and it seems like really odd behaviour. Please post more details: A screenshot of your hierarchy for these objects, their inspectors, and scripts controlling the rotation.
If you check the link provided, you can see it in action. That's using LookRotation.
https://www.dropbox.com/s/2wp1omxaasfwjc9/Unity%203D%2010.31.2016%20-%2021.12.21.01.mp4?dl=0
Behaviour is the same, as they both rotate the children constantly. Even in a new project, this is still an issue to me. On different computers and on different Unity versions.
https://www.dropbox.com/s/kl3cgcxpa1y4j4i/Unity%203D%2011.14.2016%20-%2022.46.45.01.mp4?dl=0
This is by creating a new scene, and using a script that will rotate randomly the objects. As you can see, they move the object slightly when they are close, but once they are far enough it gets really bad :(
That's really weird. Almost looks like a bug, but I'd like to actually see your code before saying that. Post it up and I'll try it out in 5.3.4 to see if the issue persists.
Answer by Naphier · Nov 14, 2016 at 09:35 PM
It appears that children with non-trigger colliders get aggregated into the parent's rigidbody. So rotating these children is adding some force to the parent.
So you have a few options:
Add kinematic rigidbodies to the children
Change the child colliders to triggers
Remove the child colliders
Probably a few other options, but having the children with colliders is what is messing it up. Thanks for teaching me something!
Can't add any form of rigidbodies to the children, as that will defeat their purpose
Can't have triggers, the children need to have physical collisions
This won't be too realistic....
I would have expected the behavior you said, but only if I used physics to rotate them :/... but it does make sense even so.
However the only solution that I know of currently that could probably fix this are Joints. I tried that, the problem was if I instantiated something and attached it to the same points, they would glitch out, because the parent collider and the thing I was attaching were conflicting with each others...maybe I needed a different layer. I will look more into joints.
The different layer idea might actually work for your current setup. Give it a shot. I know it's really only for collision detection, but maybe it also prevents child colliders from being aggregated into the parent rigidbody. The other solution is to not make these children of the rigidbody, but exist in their own hierarchy and have that new parent just match the transform of your current parent. That's likely the way I would do it, but I'm not fully apprised of your constraints.
Constantly moving objects to a position wouldn't be 100% ideal. I will try the layer one with the Joints maybe, so that things don't collide with each others
Your answer
Follow this Question
Related Questions
Have an object bounce off colliders instead of drift 2 Answers
How to make a RigidBody not go into ground when tilted foward? 2 Answers
Instantiate GameObject to specific position on the Parent 2 Answers
Rotation Complications + rotation with parents and children? 1 Answer
Is it possible to rotate a child object regardless of the parent rotation ? 1 Answer