I’m relatively new to Unreal and Blueprints in general. I’m making a simple space fighter flight sim game, and I’ve currently discovered what Gimbal Lock is.
There are a few resources around, but many of them aren’t quite designed with my method of movement in mind as far as I can tell. I wanted to ask if anyone could help me solve this issue within my own blue print framework.
The way I handle movement for my ship is that I have a single forward moving vector derived from the static mesh facing direction, and player input rotates the static mesh:
Gimbal Lock is not a math problem, it’s a wrong-framing-of-the-problem problem.
In space, there is no global “up,” and thus, you should not use representations that believe that that’s the case. Thus, you should only ever rotate things based on local coordinates. E g, given the local orientation, rotate clockwise around the local forward vector, or whatever.
There are some blueprint quaternion libraries you can use, or you can simply use “create rotation around vector” to get a Rotator that allows you to rotate the spaceship. The most important part to remember is to not keep any kind of global orientation.
Also, for a space sim, it might make most sense to simulate the ship as a physics body, and “drive” it using forces and torques. The Unreal physics system uses kinda weird units, so you often need to crank the size of the forces/torques up much higher than you’d expect in other physics engines, but once you find the right scale, it works pretty well.
Thus, “turn right” might just be “apply torque to rotate clockwise around the local up vector.” If you don’t want the free-fall “rotate forever” behavior you will get when doing this, you can add a noticeable rotational and linear damping term – something like 0.05 might work OK to start with.
Thank you! This actually worked: I replaced the “Set World Rotation” with “Add Local Rotation” and removed the Get World Rotation. Now it works perfectly!