Getting z angle from rotation (SOLVED)

Hello,

I want to get game objects z angle from its rotation. But I couldn’t figure out how to get z angle of quaternion.

Thanks.

Dont know if there is any easy way to do that? Maybe if you can read the “euler” property somehow (as you can animate it) but I dont think so.
It’s really not a simple thing as well as a quat can be translated in multiple different ways to euler. (depending on axis order etc)

1 Like

What will you do with the angle once you have it?

If angle is bigger than 100 I will call a function.

go.get(go.get_id(), “euler.x/y/z”)

3 Likes

In the case you just have a quaternion, and want the axis angle representation, you can find it using the conversion formula:

local q = myquaternion
local angle = 2 * math.acos(q.w)
local factor = 1.0 / math.sqrt(1-q.w*q.w)
local axis = vmath.vector3(q.x * factor, q.y * factor, q.z * factor)

So, as long as you remember the formula (or that the AxisAngle representation exists), you can quickly find the angle.

7 Likes

It worked. Thank you so much :slight_smile:

1 Like