Has anyone written a function to do the opposite of vmath.quat_rotation_z? That is, convert a quaternion to radians of the z-axis.
My code uses radians but when getting the rotation of a GO, it is returned as a quaternion (which I don’t know how to use).
1 Like
If you are only rotating in 2D, it should be:
local a = 2 * math.acos(q.w)
If the rotation happens around a (normalised) axis (x,y,z) with angle t radians, the individual elements are:
local s = sin(0.5*t)
local c = cos(0.5*t)
local q = vmath.quat(s*x, s*y, s*z, c)
I can recommend using quaternions instead of radians, it can simplify things after the initial learning bump.
5 Likes