Here's my code:

import bge
from bge import logic
from math import degrees

def mimic_process():

    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)

    rotation_fix_x = own_rotation_x - own_rotation_y

    if (own_rotation_x > mimic_rotation_x):
        own.applyRotation((rotation_fix_x, 0, 0), True)

    keyboard = bge.logic.keyboard

    if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.OKEY]:
        own.applyRotation((0.01, 0, 0), True)


The line rotation_fix_x = own_rotation_x - own_rotation_y is the cause of the problem. I got my object's rotation, put it in a variable, did the same with another object [the mimic object], and attempted to subtract them out. I don't know why it wont subtract them. How can I fix this? Thanks.


Only use the formatting strings "%.0f" % degrees(mimic_rotation.x)to format output to print statements, file etc, not to set values. The formatting converts the value to a string. Feel somewhat responsible as this was taken from my answer to your question https://blender.stackexchange.com/a/41328/15543.

Use round or floor if you want just the integer part here, although I'm not really sure what you are trying to achieve. Are you trying to restrict values to whole degree amounts? As pointed out previously blender uses radians as its default unit. http://bgepython.tutorialsforblender3d.com/GameObject/applyRotation

rotation_fix_x = own.rotation.x - mimic.rotation.x
if own.rotation.x > own.rotation.y:
   own.applyRotation((rotation_fix_x, 0, 0), True) 

The above would work ok because it is dealing in float types, but wouldn't set to a whole degree amount. Here is some console code from bpy looking at the rotation_euler.x of an object

# rotation.x in radians
>> C.object.rotation_euler.x
# rotation as degrees.
>>> x = degrees(C.object.rotation_euler.x)
>>> x
# rounded to a whole number
>>> y = round(x,0)
>>> y
# how much to add to C.rotation_euler.x to make it whole number in degs.
>>> fix = radians(x - y)
>>> fix

To step in degrees use radians(1) when applying your rotation from the kb.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.