MouseOrbitImproved slanted orbit
Hello everyone!
I am currently encountering a bit of a problem regarding the MouseOrbitImproved script for Unity (which can be found here).
Summary
In my game, the player can be sent sideways to a wall and gravity would change towards the wall. I would want the player to still have full control over the camera, just that the camera would flip sideways (this can be omitted from the requirements) and the camera controls would be different (for example, when I move the mouse up, the camera would rotate around the player since the Y is the new "X" when on the wall).
Problem
I will admit that I haven't fully understood how this script exactly works (however, I did understand some basics) so I was expecting to run into problems... just not this tedious. I modified the script in such a way that it uses other variables from other scripts to know when the gravity changed. The most occurring problem that I had was this. Whenever I did the condition to check if the gravity was against a wall, I inverted the X and Y values (since those are the only ones I needed to change from what I know). So, instead of this:
// for normal gravity (or ceiling gravity too)
x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
y = ClampAngle(y, yMinLimit, yMaxLimit);
It becomes this:
// for wall gravity
y += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
x -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
x = ClampAngle(x, yMinLimit, yMaxLimit);
However, it doesn't appear that simple. Whenever I invert the X and Y, whenever I try to rotate in the new "horizontal" axis (which is Y) at the maximum value of the new "vertical" axis (which is X), the orbit is slanted. However, when the new "vertical" axis is at the minimum value, it works fine. Here are 2 images below to further explain what I mean.
What I want as a result:
Actual result I have currently:
The red cube represents the player and the circle outline represents the camera orbit and the plane represents the wall.
I hope this is enough information! If you have any questions or would like me to improve this question, feel free to tell me! Thank you all for the help! :)
P.S. Kindly know, if you are going to send me sample code, send it in C# since that is what I am using to code the game. Thank you!