I would like to know if its possible to keep gravity oriented to the Y coor of a ship mesh so that players riding aboard a ship will always be oriented correctly and not fall about when the ship pitches and rolls in space?
Also, this has to be a localized to the one ship since other ships will have their own localized gravity within them. All the ships of course will be floating in open space with no gravity, so the localized gravity sphere can not extend beyond the ships mesh.
I know this seems complex, but right now I just need to get it working on one ship.
2 Answers
2
Well, first you have to tell us how your player setup looks like...
Just some points:
- A CharacterController can't be used in this case because you can't rotate it except around worlds y-axis.
- So you would need to use a Rigidbody instead. Since Physics.gravity affects all Rigidbodys you can't use the "normal" gravity. That means you have to turn off "use Gravity" on all Rigidbodys and add this force yourself.
- You would also parent the player to the ship when he's inside, otherwise if the ship is moving / turning fast the player would bounce around through the ship and finally fall through the floor (due to collision errors).
So apart from that you have to create your own player controller script. Something like the CharacterMotor script that comes with Unitys Character-package. Even in this script the gravity is applied manually but always in worlds negative y - axis (-up or down).
In the end all you have to do is using AddForce and apply the gravity to your player. The gravity vector you can get from the ships transform (just use -transform.up)
When the players board the ship, simply add the players as a child object to the ship, and disable the rigidbody on the players. They will then be aligned to any transforms the ship makes.
That seems to have sorted it - removing audio compression on all the repeatedly used sounds. (which we reused the audiosources of after they finished playing - that might have been significant - compression seems to make it crash occasionally). Hope this helps someone else getting random sound related freezes googling this thread at some point in the future :)
– Flimgoblin