4
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – joH1
    Commented Aug 27, 2016 at 15:19

1 Answer 1

1
$\begingroup$

Removing the then inside of the if statements and replacing the - and + with -= and +=:

def mimic_process():
    if own_rotation_x > mimic_rotation_x:
        own.worldOrientation.to_euler.x -= 1
    elif own_rotation_x < mimic_rotation_x:
        own.worldOrientation.to_euler.x += 1
$\endgroup$
1
  • 1
    $\begingroup$ My object isn't rotating; although, own.applyRotation ((0, 0, 0), True) works. $\endgroup$
    – blackhole
    Commented Nov 11, 2015 at 21:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .