# Setting A Circle's Rotation From A Changing Number in the BGE

I have a timer that counts from 82 to -82 and back.
And I have a circle that should rotate (x rotation) from 82 to -82 and back.

How can I assign the timer number to the x rotation number of the circle?

My code so far is:

cont = bge.logic.getCurrentController()

circle = cont.owner

matrix_rotation = circle.worldOrientation

euler_rotation = matrix_rotation.to_euler()

degrees_rotation = [math.degrees(a) for a in euler_rotation]

circleRotation = int(degrees_rotation)


Now I want to reverse the steps but don't know how to do it. The timer is driven by the system time and the circle should spin accordingly (it is kind of a skybox).

All your need to do is take your timer's output (the timer var in my script), convert it to radians and then insert it in the object rotation vector.

import bge
import math

cont = bge.logic.getCurrentController()
circle = cont.owner

circle.worldOrientation = (x, 0.0, 0.0)


The reason for the math.radians() conversion is worldOrientation is a vector storing the rotation for the X, Y and Z axes in radians.

As a side note, a much simpler way to get the rotation of a object in degrees is with these two lines. I used the same variable names you did to make it easier to see where it would fit in.

euler_rotation = circle.worldOrientation.to_euler()
circleRotation = math.degrees(euler_rotation)

• Thank you so much for your help David! I've tried it, however the circle always seems to spin around a different axis as I want it to... If I hook up a simple motion actuator and let it rotate in the x axis all is fine. There must be a mistake somewhere...? Thanks again. – Sputi Mar 17 '15 at 8:34
• @Sputi First apply the rotation of your circle. Then try running the game again. – David Mar 17 '15 at 12:29
• Applying the rotation did the trick. Thank you for your help! – Sputi Mar 17 '15 at 13:11
• Uhh.. still a problem: the circle doesn't make a 360 degrees spin but only 180 and then goes all the same way back to 0 again. Is there a way to tell the circle to make the full spin instead of two half spins? – Sputi Mar 17 '15 at 16:15
• Ok that full spin works now, was a mistake in my part, but the circle now does a full 360 and then rotates the same way back instead of keeping on rotating the same direction... any ideas? – Sputi Mar 17 '15 at 16:54