title: Unity. Attempting fake internal ship gravity. Rigid body children of rotating object keep sliding around
body: <p>I'm attempting to simulate a ship/space station with internal gravity.</p>
  
  <p>To accomplish this, I'm making the player and all contents of the ship children of the ship. The ship itself has colliders, but no rigid body components. The idea is that as the ship moves, so will all of its contents. Pretty straightforward so far.</p>
  
  <p>To simulate gravity in the ship, the player controller and all rigid bodies have the default gravity turned off. Instead of the standard, each frame a force is applied along the negative up vector of the parent ship.</p>
  
  <p>This sort of works, but there is one major problem that I have to sort out before this thing is solid. All rigid bodies slide around the interior of the ship very slowly.</p>
  
  <p>I'm aware that this is probably due to the updated position of the floor combined with the gravity force resulting in some kind of shear force. The objects always slide against the rotation of the ship.</p>
  
  <p>I've tried mucking around with all of the physics properties from Physic materials to drag to mass, etc. None of these have worked, and I'm pretty sure it's due to the fundamental fact that the floor is moving, even though the RBs are children of the object that the floor is a part of.</p>
  
  <p>Anyone have a solution to this that isn't some kind of duct tape? I could try to make everything kinematic and only "wake up" when certain external collisions occur or something, but that could get very cumbersome. I need for this to work in as much of a general purpose way as possible.</p>
  
  <p>Some code:</p>
  
  <p>On the ship</p>
  
  <pre><code>void Update () 
  {
      transform.Rotate(new Vector3(Time.deltaTime * 0.125f,Time.deltaTime*0.5f,0));
  }
  
  void FixedUpdate()
  {
  Vector3 tempVec;
  
  foreach(Rigidbody rb in rigidBodies)
      {
          //Gravity!!
  
          tempVec = transform.up * -9.81f * rb.mass * Time.deltaTime;         
          rb.AddForce(tempVec, ForceMode.Acceleration);
      }
  
  }
  </code></pre>
  
  <p>I've also worked on a version where the ship was following the movements of a rigid body. I couldn't do direct parenting, so I had to simply set the transform manually each frame to match the physics proxy. This still had the same effect as above, though it's probably ultimately how I want to move the ship, since that will tie into the flight mechanics more properly.</p>