# Get the rotation of an object in the game engine

How would I get an object's rotation and set that as another's velocity? Like if I had Object A, that has the rotation data, and Object B, the object to be moved. How would I get that working in python?

Because of some confusion, here's some of the code:

Gun = bpy.data.objects["Gun"]
rotationOfGun = Gun.globalOrientation

• So you want to get an object's rotation vector and use that to set another object's velocity? – Daniel Pendergast May 30 '13 at 0:30
• That's exactly what I need to do. – V360 May 30 '13 at 0:32
• I assume that you're using a rigidbody? – Daniel Pendergast May 30 '13 at 0:34
• no, just a Dynamic – V360 May 30 '13 at 0:42

The method for accessing an object's rotation varies depending upon which rendering engine you are using.

In either Blender-Internal or Cycles, you can access an object's rotation by using the Python reference bpy.context.object.rotation_euler or just object.rotation_euler. In your script, just call that reference and set your other object's velocity based on that.

In the Blender Game Engine, you need to instead use object.worldOrientation.to_euler() to retrieve the object's rotation. For example:

from bge import logic
cont = logic.getCurrentController()
obj = cont.owner
rotation = obj.worldOrientation.to_euler()
print (rotation.z)

• It says this when I try to run it: Traceback (most recent call last): File "<blender_console>", line 1, in <module> TypeError: 'bpy_prop_collection' object is not callable – V360 May 30 '13 at 1:22
• Did you type ...euler or ...euler() ? – Gwen May 30 '13 at 1:35
• This is game-engine you should not use bpy! – dfelinto May 30 '13 at 2:40
• @V360 I caught my mistake. I had assumed you were using Cycles, but the commands are different in the Game Engine. Try using obj.worldOrientation and let me know if that works. – Gwen May 30 '13 at 4:47
• @V360 Check the code snippet I added in. It works for me in Blender 2.66a. – Gwen May 30 '13 at 23:02