3
$\begingroup$

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[1])

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).

$\endgroup$

1 Answer 1

2
$\begingroup$

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

x = math.radians(timmer)
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[0])
$\endgroup$
5
  • $\begingroup$ 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. $\endgroup$
    – Sputi
    Commented Mar 17, 2015 at 8:34
  • $\begingroup$ @Sputi First apply the rotation of your circle. Then try running the game again. $\endgroup$
    – David
    Commented Mar 17, 2015 at 12:29
  • $\begingroup$ Applying the rotation did the trick. Thank you for your help! $\endgroup$
    – Sputi
    Commented Mar 17, 2015 at 13:11
  • $\begingroup$ 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? $\endgroup$
    – Sputi
    Commented Mar 17, 2015 at 16:15
  • $\begingroup$ 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? $\endgroup$
    – Sputi
    Commented Mar 17, 2015 at 16:54

You must log in to answer this question.

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