Gravity inside a space ship

Hey there, I’ve been a long time reader of the answers (going on a few years now!), and I have come across something that requires someone more capable than me to figure out.

I would like to simulate gravity inside a space ship as the ship is moving. I would like the players to be able to walk around inside the ship and help the other players. I have no problem with networking this (I’ve already done so), but the internal gravity can’t be done so easily.

I have tried to use a character controller although they cannot rotate around anything but the global Y axis, and I know that rigidbody children can’t be inside a rigidbody parent. Even knowing that, I tried anyway.

I got the rigidbody character to have a constant force applying downwards along the local Y axis and then captured the velocity of the ship and applied the ships current velocity to the character while zeroing out the Y velocity. This kind of works, although in Multiplayer the characters glitch around immensely and from the point of view of the player they are vibrating.

Is there any other way to simulate gravity?
i.e. probably not involving rigidbodies or character controllers.

Any advice is greatly appreciated!

Does the physics engine correctly simulate centrifugal force? That’s what I imagine when I think of spaceship gravity; the crew compartment of the ship is rotating at a constant speed to provide 1G of downward force against the walls, you can walk all the way around and if you climb up a ladder to the center you will become weightless and flip around. Like the ship in 2001.

If you can’t automatically get that effect, you could simulate it by finding the distance from the ship’s Z-axis centerline in the XY plane. It might be easier to do that with two levels of transforms- one goes forward or backwards along the ships z axis to where the player is, then measure from the player to that one, and apply acceleration away from it.

I’m not sure if that’s what you’re talking about though.

The other way, if your spaceship has got some Star Trek style warp drive is to just apply a 9.8 m/sec/sec acceleration to everything on the -y axis. (the spaceship’s local y axis, not the player’s). Do it in Update, and use Time.deltaTime.

You can still use rigid bodies and colliders, just turn off their gravity.

-edit- Is there any reason why the inside of the spaceship needs to be actually inside the spaceship, and not a separate "set, " elsewhere in the scene, viewed by its own camera which you switch to when appropriate?