- Home /
Parenting Rigidbodies to Rigidbodies (Newtonian Space)
Good evening everyone.
I'm sorry if I should have been able to find the answer to this myself. I have tried, and failed.
I've got a simple space game. I want the character's object to be able to walk around inside his ship as well as pilot it. I've got state changes working fine, no issues there, but if you leave the pilot's position after adding some force (the player is kinematic while piloting) you then get left behind by your ship, or at best spun around inside the cockpit. How should I fix this?
The player's object needs to inherit changes in rotation and position, in the same way a parent-child transform hierarchy does, but also have its own movement abilities.
Joints are out because I need relative movement (unless it can be done with ConfigurableJoint, but I can't see how). I can't just use transforms or isKinematic on the character because that will just delay the issue until small ships have to dock inside big ships. Parenting the transform normally doesn't cause motion to be inherited. I've tried having them parented from scene start and dynamically parenting. It doesn't seem to make a difference whether the child is under the root ship object (with rigidbody) or some child object (no rigidbody, which is strange because it should work fine...)
If I switch to Editor while the ship is spinning and manually move it using Gizmos, then the character moves along with it, no issue.
My only solution would be to recursively apply any force to all child rigidbodies as well, but then there's pivot point problems and it will get stupidly expensive for ships with large hangars.
Quick View:
A parent rigidbody makes changes to a transform.
All non-rigidbody children behave as expected.
Any rigidbody children do not inherit the parent's changes.
I need them to.
Thank you for your time and help,
James.
I tried a rigidbody pilot childed to a rigidbody ship, and it worked fine - better yet when the pilot was set to kinematic: it always followed the ship, no matter which external forces were applied to the parent.
I can easily reproduce my issue, I'd like to know how you avoided it:
Create two default Cubes, apply rigidbodies Deactivate Gravity in Edit>Project Settings>Physics (makes things easier to see) Add a ConstantForce to both of them, one pointing Z+ and one X+ $$anonymous$$ake one the child of another If you play, you'll find they go off on their separate axes... However, the expected behaviour is that both should move with the parent's ConstantForce, and one should move in a different direction as well due to its own ConstantForce, resulting in a diagonal line movement.
How were you applying your forces? I'm aware that it works when the pilot is kinematic, but sadly that's not an option for me.
Your answer
![](https://koobas.hobune.stream/wayback/20220613070028im_/https://answers.unity.com/themes/thub/images/avi.jpg)