x


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.

more ▼

asked Apr 07 '12 at 02:29 PM

TheWyrdsmith gravatar image

TheWyrdsmith
30 1 1 1

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.

Apr 07 '12 at 04:51 PM aldonaletto

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+ Make 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.

Apr 08 '12 at 05:13 AM TheWyrdsmith
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1864
x1781
x135

asked: Apr 07 '12 at 02:29 PM

Seen: 709 times

Last Updated: Apr 08 '12 at 05:13 AM