Note that there are some explanatory texts on larger screens.

plurals
  1. POUnity. Attempting fake internal ship gravity. Rigid body children of rotating object keep sliding around
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COOne solution is general but not simple: Create a static copy of the ship somewhere (rigidbody + colliders only), that contains copies of all the rigidbodies + colliders within the ship. Whenever a force would be applied to the ship that should move things inside, apply it to the shadowed rigidbodies. Update the localposition and rotation of the objects inside the ship to match the shadowed rigidbodies. This ensures the ship-internal frame of reference is static for the physics engine—and the rigidbodies will sleep correctly too.
      singulars
    2. COThat's sort of what I did when I implemented this in XNA with a 3rd party physics library a couple years ago. It was cleaner there, though, because I could have entirely separate physics worlds and then transform the interior contents to match the boxes representing the mass of the ship in the global world. In this case I wonder if I could get away with putting all of that stuff at the origin, but layering it and keeping it invisible so it doesn't interact with the rest of the world.
      singulars
    3. COThat should work--though if you have a lot of such ships to model you'll run out of layers.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload