Camra Math problem with Custom Gravity

Hello everyone,

im new to unreal engine and struggeling a bit with the vector math when using custom gravity. I am using this tutorials code: Custom Gravity in UE 5.4 | Tutorial to calculate the camera rotation when gravity changes. I commented out the block that makes the camera automatically compensate for gravity rotation. instead i want to allow a full 360 degree camera in my case. the issue is that the math of this setup does not work out when my pitch goes >= ±90deg. From my understanding the cause of this is the fact that to calculate the difference between the camera position and the current gravity direction the code uses FindBetweenNormals.

FQuat GravityRotation = FQuat::FindBetweenNormals(GravityDirection, FVector::DownVector);
return (GravityRotation * Rotation.Quaternion()).Rotator();

For the purpose of this function a pitch of 45deg or 135deg should result in the same offset since it both just gets compared as a vector to the gravity direction vector. So if i look at a angle of 45deg, then change my gravity by 90deg the camera calculates the new position as a frontal view of my character instead of a 135deg pitch.
So the actual camera vector doesnt change but it rotates around that vector.
While i do now understand the issue, i have honestly no clue how to do something about it. So im hoping for your help and hope i made my issue understandable ^^ Thank you very much in advance!

findbetweennormals only gives teh shortest twist between two vectors, so it drops any spin around that axis. that is why 45 and 135 pitch look the same to it and why it flips near 90. build your camera basis from forward instead. take camera forward, remove the part along gravity to get a flat forward, then rebuild up from that. that keeps pitch continuous through vertical and you keep full 360 roll on top with local roll only.

you can also try Gravity and Ballistics Toolkit, a custom gravity plugin for Unreal Engine that keeps camera and movement aligned in gravity space: Gravity & Ballistics Toolkit — Planet Gravity, Zero-G & Arc Prediction | Fab