Independently moving Rigidbody inside a moving Rigidbody

Hi everyone,

I only had a couple hours last night to test or figure this out and it’s been bugging me all day at work thinking of a solution.

I want to have a rigidbody controller inside of another rigidbody based vehicle.
So the simplest scenario would be a box with a rigidbody that moves and spins and accelerates. And inside I can have my character move using physics with the inside of the ship as it’s own reference frame. So changes in velocity wont throw it around. But also since the character is physics controlled, it also knocks the ship around like when it jumps into a wall. Making the mass of the box so large that it cannot knock it around though realistic, I dont really like :stuck_out_tongue:

When they are transform based movement character controllers and the cube moves using transforms and the character is a child of the box then it all works fine, but I like the natural movements simulated using a rigidbody for the box and character.

One idea ive had could be to have the rigidbody vehicle in the game area and moving around, inside it would have the character with the camera attached to it. Then FARR away from the real vehicle is a non-moving non-rigidbody copy of the real vehicle with the same character inside which is being controlled by the player with its physics based movements and restrictions. And this character just moves the one with the camera in the same way, so the player wont know its sort of remote controlling the character in the real vehicle.

I havent gone about implementing this option. It sounds fairly complicated so Id like to explore other options too. Any features of Unity I dont know about which could make this simpler?

I’ve sorta asked a similar question that got me to this point and I was satisfied with it earlier but Ive come back to this and am trying to extend what I can do with it.

Ok I did the solution I said in the 4th paragraph and OMFG it is such a smooth effect.

So for the record of anyone trying to make a game in space where you can walk around inside a moving vehicle and both are controlled by physics.

Have an exact copy of the colliders flat somewhere far away from your scene, I made a ‘Ghost’ script which set the local position and rotation of a working camera and animated body in the real ship and the collider and Off camera are controlled by the movement and looking scripts.


I know this is an old thread, but i had the same problem, and i came up with a different solution:

I split my spaceship object into a floor and an insideobjects sub gameobject. The floor has a rigidBody and a collider, not the parent spaceship. This way, the floor is simulated and moves wia the physics engine, but the insideobjects is not moving with it. After that i just move and rotate the insideobjects gameobject in LateUpdate where the floor is.
With this way the simulated rigidbodies inside the insideobjects layer do not get any force by the floor rigidbody simlulation. I love this, because everything is in the same position where it should, and no rendering hacks needed.