[Solved] How to get actual object rotation?

I need to get owner’s rotation in degrees or something angle related. But, I just found worldOrientation property determined by 3x3 matrix.

Actually, I have object which rotate around Y axis and I try to write script that will change object rotation speed when it reaches desired angle. This is very hard to me to do with 3x3 matrix.

Thanks!

The type of owner.worldOrientation is an orientation matrix, which is basically a 3x3 list, with the first row being a point that the X axis is pointing to, the second row a point that the Y axis is pointing to, and the third being the point that the Z axis is pointing to. Each row has 3 values which represent X, Y, and Z coordinates.

This matrix is called the “identity” matrix, but you can think of it just as the normal, nothing-is-rotated-or-scaled matrix.


[[1,0,0] #x axis points at the point (1,0,0)
[0,1,0] #y axis points at the point (0,1,0)
[0,0,1]] #z axis points at the point (0,0,1)

Thanks to a useful utility called Mathutils, you can easily find rotation in degrees, if that’s what you’re after.


import GameLogic as g
from Mathutils import *

c = GameLogic.getCurrentController()

ori = c.owner.worldOrientation
ori = Matrix(ori[0],ori[1],ori[2])

eul = ori.toEuler()

c.owner['zRot'] = eul[2]

This script puts the Z rotation (in Degrees) into a variable called “zRot”. eul[0] would, similarly, get the X rotation.

Attached is an example blend… use the Z key to rotate the object.

Hope that helps!

-Sam

Attachments

eulerRotation.blend (33.6 KB)

Yeah, it succesfully converts it into degrees.

Thanks a lot Sam! :slight_smile:

This was so helpfull thank you