- Edited
I'm creating a game that's happening on the surface of a planet. I have some issues with the movement system, because everything was working correctly until I got to the south pole (gimbal lock). So I decided to get more in-depth knowledge about quaternions, but I ran into somehting I don't understand.
Here are 2 characters on the surface of a sphere. The right one is exactly on the north pole. The RGB lines are the basis and purple is the position vector (normal of the sphere surface). As you can see they are aligned with basis.y.
#the code used for rotation in _process
var axis = global_position.normalized()
var angle = fmod(quat.get_angle() + delta * SPEED, TAU)
quat = Quaternion(axis, angle)
basis = Basis(quat)
Then this happens. If I understand correctly, the quaternion should rotate the character around the axis (which was aligned with the basis). So why does the mouse tilt?
I mean it DOES rotate around the axis, just in a weird way.
I've also tried to apply the quaternion as
rotation = quat * rotation * quat.inversed()
Edit: I'm asking this question here, because I've used some interactive quaternion visualization from 3Blue1Brown (https://eater.net/quaternions/video/intro) and I feel like the quaternion part is alright, but I don't know how to apply it specifically in Godot, but I may be completely wrong.