Vector Rotation

I am working on a Marble Madness type game and for the movement mechanics trying to simulate the effect of moving the marble as if the player is actually tilting the ground (e.g. Tilting the ground from center along x and y axis would cause gravity to make the ball roll) but instead of actually rotating the level (ground) I want to calculate the vector for the force of gravity according to user input. I am encountering gimbal lock and do not know how to get around this. I have tried looking into quaternions and that is beyond me at this point.

How I currently have this setup:
On Tick I calculate the current X and Y angle of tilt and then rotate the vector by that rotation. So, every frame I rotating a 0,0,(Gravity) Vector.



I have recorded a video showing the resulting Gimbal Lock:

The yellow debug line represents the Force Vector, when X and Y Angles change individually it is fine but later in vid you can see how when they change simultaneously the Vector does not rotate properly.

Thank you for any possible help with this.

Hi man,

the simplest trick to avoid gimbal-lock for me , is create an extern actor and apply relative rotation to him.
For unkown reason, applying relative rotation to something in the actor himself produce the evil gimbal lock.
Try using a simple actor with an arrow and check it

Plus:
if you plan to work only with perfectly spherical, you dont really need to use the force calculation.
Use some math to apply vectors to move , calculate rotation separately from the movement.

Thanks for this, I am actually looking for a proper method just for the sake of mastering properly instead of lookig for a “Hack”. However I still appreciate your response and would like to ask you some clarity on what you are referencing.

I am not clear what you mean by create extern actor and apply relative rotation, and then you say to use a actor with an arrow and applying relative rotation to something inside the actor creates Gimbal Lock? My guess is that what you are suggesting hass something to do with creating a situation in which the engine natively uses and calculates Quternions for rotation instea of Euler Angle rotation? I get that I could create an arrow, have the arrow start by facing the direction of the gravity, and then rotate the arrow and get forward vector which would give me a normalized directional vector for the force and then multiply by the force of the gravity to get the proper length. But I am not clear where to put the arrow if it cannot be inside an actor or an actor itself?

Unfortunately I am not clear on your second part either, I am using a force to move the ball, but I have to calculate the direction of that force, the rotation of the ball is handled by friction and the physics engine. The rotation I am trying to calculate is the direction of the force. When you say use some math to apply vectors to move, are you saying rotate a vactor on the X axis, rotate a second vector on the Y axis and do some mathon those to vectos to get a proper single vector direction for the combined force? If so, any idea on what that math is? Adding? Subtracting? Dot? Cross? If so and you do not know the math at least will give me something to look up and figure out the proper math.

Thanks again for your thoughts!

Hi man,
Sorry for not being clear enough
Hope to fix it here!

My dirty experience is :
If i use add relative rotation , in an actor “BOB” to rotate one of his meshes, i end up in a gimbal lock, This happenz when i try to rotate him along all axis,

I just want to rotate it like the rotate tool does in the engine, whats the problem?
Unreal have his own secret moves to avoid Gimbal lock.

I found that , if i make another actor “JacK” and apply relative rotation to the whole actor , it will rotate perfectly , without gimbal lock.
So for rotate The mesh of BOB, i create a JACK and rotatet him, and clone his rotation to BOB mesh.


Another solution to the gimbal lock.

There is a node to create a Rotator, from Vectors,
You can take the Up-Vecro the Right Vector and the Forward vector of something, Rotate them using Rotate Vector, an plug all them in the Make rotator from vectore

I used it here to mirror a rotation How Mirror a rotation ? (Solved) - Blueprint Visual Scripting - Unreal Engine Forums

This is the cleanest way i know.


For the ball, if you are using the fricction to calculate the rotation , ok , its ok.
I was just saying that if you dont need a super realistic stuff.
You could just move the ball like a point, with no body, and after , make some extra work to calculate the rotation in base of movement .
Forget it