# Rotate object in python in BGE?

Here's my code:

import bge
from bge import logic
from math import degrees

cont = logic.getCurrentController()
own = cont.owner
own_rotation = own.worldOrientation.to_euler()
mimic = own.parent
mimic_rotation = mimic.worldOrientation.to_euler()

own_rotation_x = "%.0f" % degrees(own_rotation.x)
own_rotation_y = "%.0f" % degrees(own_rotation.y)
own_rotation_z = "%.0f" % degrees(own_rotation.z)

mimic_rotation_x = "%.0f" % degrees(mimic_rotation.x)
mimic_rotation_y = "%.0f" % degrees(mimic_rotation.y)
mimic_rotation_z = "%.0f" % degrees(mimic_rotation.z)

def mimic_process():
if own_rotation_x > mimic_rotation_x:
then own.worldOrientation.to_euler.x -1
elif own_rotation_x < mimic_rotation_x:
then own.worldOrientation.to_euler.x +1


I am fairly new to python. I am trying to get an object to, every single 2 GE ticks (didn't specify that in script yet), an object add/subtract/do nothing to its rotation to try to match another object (in this case, parent). I get an error the line following the function. I am trying to fix my current code I have for the function, but I don't quite understand how to directly add/subtract/do nothing to an object's rotation based off what I have so far. How can I rotate this correctly? Thanks.

• to_euler is a function. You need to add brackets to the expression to call the result and not the function itself: own.worldOrientation.to_euler().x check the blender console for details on script errors. – joH1 Aug 27 '16 at 15:19

Removing the then inside of the if statements and replacing the - and + with -= and +=:
def mimic_process():