# Get rotation of object without decimals?

import bge
from bge import logic

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


Here's my code (above), which works fine, but the console prints really long digits. I am trying to get an object to rotate according to another object's rotation by taking the objects rotation, comparing it to the other, and adding/subtraction to x, y, or z. The problem I have is that the rotations have decimals when they aren't supposed to (, or atleast I think). The object has 0, 0, 0 as its rotation when I go to the object panel, but if I add 10 degrees to z, the script will print a long number (10.01231234923) when I added 10 and only 10. The object is static. In other words, I dont need the small and specific value. How can I have it only print the whole number, i.e. without decimals? Thanks.

• What if you wrap it with round()? So print(round(rotation.x, 2)) where 2 is the number of decimal places to leave? – gandalf3 Nov 10 '15 at 1:42

round() the numbers before printing them:

print(round(rotation.x), round(rotation.y), round(rotation.z))


Blender uses radians natively for rotation. You see degrees in the panels because the default setting for Units under Scene properties is to show degrees.

There are only 2Pi radians in 360 degrees, hence 10 radians is more than a revolution. To add 10 degrees to a rotation use the radians(degrees) method. eg rot += radians(10)

You can use formatting when printing to reduce the amount of decimal places. %.0f prints a float (decimal) type with no decimal places. %5.2f is print a float in a 5 digit field with 2 decimal places.

import bge
from bge import logic
from math import degrees

cont = logic.getCurrentController()
obj = cont.owner
rotation = obj.worldOrientation.to_euler()

print("%.0f" % degrees(rotation.x))
print("%.0f" % degrees(rotation.y))
print("%.0f" % degrees(rotation.z))