I am currently trying to make a puzzle game using gravity, similar to the planets in Super Mario Galaxy, except the player’s gravity is dictated by the arbitrary face of the object it is currently standing on or runs into. Determining the gravity’s direction was easy as I am just using a box trace to get the normal of the object and then use the negative as the gravity. The issue is trying to rotate the player only on the local x and y since I want the player to be facing roughly in the same direction when the gravity changes. I.e. if the player runs face first into a vertical wall that is 90 degrees from the ground they’re currently standing on, they should only pitch up 90 degrees and be now facing upwards but if the player runs into a 90 degree wall from their right side, they should roll 90 degrees to the left, and so on.
So far I have tried make rot from z of the normal, which aligns the player to the normal, but rotates the player to the same rotation regardless of how you approach the wall. I have tried dividing the dot product of the normal and the up/right vector of the player with the product of their lengths to manually find the pitch and roll, but it results in seemingly random rotations that sometimes are what I am going for but I am unsure what I am doing wrong with that.