I want to make a bot that points rotates to face it’s target. So I went looking for some examples, and found this example.
Relevant code for me being:
local current_rotation = go.get_rotation() local target_rotation = vmath.quat_rotation_z(target_angle) local rotation_speed = 4 -- tweak this! local rotation = vmath.slerp(rotation_speed * dt, current_rotation, target_rotation) go.set_rotation(rotation)
I noticed that the rotation speed isn’t actually constant here. The vmath.slerp function causes the new rotation to be (in the example) about 6.6% closer to the target rotation than the original rotation. But the closer it gets to the target rotation, the less it will move the next time.
If you excuse this excessive amount of particles being used as lines to demonstrate my point:
But I need it to rotate at constant speed. So I need to know how ‘far apart’ the two original quaternions were, how can I do that?