Get objet's rotation

Hi guys.
First : Sorry if I made mistakes, English isn’t my natural language.

So : I’m not a begginer in programming, but in Blender. So I searched a way to get an object’s rotation with Python, I found some ways, but no one works.

The last one :


from bge import logic


cont = logic.getCurrentController()
obj = cont.owner
rotation = obj.worldOrientation.to_euler()


obj['xRotation'] = rotation.x

I wanna store the “rotation.x” to “xRotation” property, but it doesn’t work. “obj.worldOrientation.to_euler()” returns nothing.
Is there an another way to do that ?

This works just fine for me. By “returns nothing”, do you mean it returns 0.0?

Yes, that’s my “logic bricks” to rotate my object :

I would double check the spelling and capitalization of the property, as it must be exact. I would also try adding a print function so you can see what the function is returning, versus what the object property is displaying. :

from bge import logic


cont = logic.getCurrentController()
obj = cont.owner
rotation = obj.worldOrientation.to_euler()

print(rotation.x)
obj['xRotation'] = rotation.x

Also, how is this script being called? In the image that you attached we can’t see what sensor is hooked up to the python controller. It is possible that this script is running only once and is indeed returning the correct rotation, but is simply not being updated.