Altering gravity in game

Hi everyone,

I’m currently trying to make a game where the character is a cube inside a box, I’d like to make it so that when the player object hits a wall, the camera rotates so that the scene appears upright and the gravity is changed so that it is now acting down relative to the camera’s rotation.

Also, if there’s a way that I can make it so that the axis are always correct relative to the camera’s rotation (up is always on the y axis, left/right is always on the x axis) so that I don’t have to recode how the character moves for every wall it would be appreciated.

Thanks in advance to anyone who helps! Sorry if this is easy, I’m new to Unity.

You can use Physics.gravity to alter the gravity inside physics simulation (also affects particle systems and maybe other things).
For the axes, it’s up to you to use the correct relative ones. Vector3.up will always be Vector3(0,1,0). It’s up to you how you will interpret this data (either as a world-space or a local-space direction). For local axes of each transform, you can use transform.up instead, which is a transform’s relative upwards direction in the world space - therefore some refactoring would be required here if you are not using these. To avoid recomputing and to keep it clean, you might use a single Transform in scene to define the current coordinate system (a single gameObject that, using its rotation, defines what’s up, what’s left and so on)
Last option would be to rotate the box/room instead, preserving the coordinate system - but this option might not be suitable if you are using static objects for your scene, or if it’s too complex or - well - It’s hard to say without seeing the scene details.