1
$\begingroup$

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)
        print('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')

    keyboard = bge.logic.keyboard

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

mimic_process()

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.

$\endgroup$

1 Answer 1

3
$\begingroup$

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
1.1093189716339111
# rotation as degrees.
>>> x = degrees(C.object.rotation_euler.x)
>>> x
63.5592952084158
# rounded to a whole number
>>> y = round(x,0)
>>> y
64.0
# how much to add to C.rotation_euler.x to make it whole number in degs.
>>> fix = radians(x - y)
>>> fix
-0.007691749642459737

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

$\endgroup$

You must log in to answer this question.

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