Search code examples
unity-game-enginegame-enginegame-physicsspacerigid-bodies

Player in Spaceship


I want to realize space game on Unity3d engine. There are some huge spaceships in the void. So, I want players flying in space in weightlessness, but when they go inside any spaceship, they will be under the influence of local gravity field of spaceship (if it is in On state).
I going to do it using addForce() function applied to rigidbodies of players towards spaceship floor. But with this approach Players will be only magnify to a floor, but not to stay on they feet automatically.
How can I put they on they feet the best way?
Or, maybe, anybody knows the completely different approach to solve this custom gravity fields issue?

PS: It will be a multiplayer game with many ships with different orientation in space with a lot of players in them. Each ship has it's own gravity field.


Solution

  • As a result I consider to applying the gravity by myself. Just note that Gravity is an acceleration, not a force. Meaning when applying I use "ForceMode.Acceleration". That acceleration could simply be the exact opposite of up direction of current spaceship. I'm talking about "-transform.up" of spaceship. I can also use same Up vector, to rotate player so that gravity actually feels right, aka. player feet are pointing towards gravity.