- Home /
How to make physics relative to moving parent
Hi Guys,
Is it possible to stop child object Rigidbodies from being affected by the parent's movement?
I'm making a 2D game where the player is on a spaceship, and can interact with objects on the spaceship or control the spaceship itself moving through space. Currently when the spaceship moves, all the child objects are impacted (e.g. ship moves forward, all child objects are dragged backwards relative to ship).
Is there a way to tell the child object Rigidbodies to treat the ship as if it were stationary, while also having the player able to add forces to move the ship through space?
(Question is similar to this one, but that hasn't been answered at time of writing: https://answers.unity.com/questions/1390654/physics-relative-to-parent.html)
Thanks in advance!
Answer by BornInABottle · May 22, 2018 at 10:36 AM
SOLVED - Got an answer on a different forum so adding it here for reference. The solution is to have the ship interior and ship exterior separate in the hierarchy, then add a script that updates the transform.position and transform.rotation of the interior to match the exterior every frame. You can then just have them on different layers so the physics don't interact. When the ship exterior moves through space via forces on its Rigidbody2D the objects inside the ship aren't affected.
I still don't understand. Can you elaborate your answer a bit more?
I'm trying to achieve the same as you. I tried setting kinematic=true and programmatically stopping at obstacles with oncollisionenter2d, but it was very jittery at high speeds I was thinking about using a 2d joint but need more research.
Your answer
Follow this Question
Related Questions
Inconsistent gravity/random forces/solver problem? (forum crosspost) 0 Answers
Is it possible to disable collisions for separate physics scene? 0 Answers
Stack of RigidBody2D, Freeze X and Z, Odd Behavior 1 Answer
increasing knockback of a rigidbody as received damage increases (like super smash) 1 Answer