rotate an object by some angle

i need to rotate an object in the bge by a particular angle using python scripting.
i m currently setting Motion actuator dRot. But that does not seem to work properly, as the object continues with the motion indefinitely.
any other function to do so?

The applyRotation function is what you want. It’s also a good idea just to read over the KX_GameObject functions to learn what you can and can’t do.

can you please give an example for the same…
i use bge.logic
it requires to set the actuator variable

own = cont.owner
move = cont.actuators[“move”]

the applyRotation uses radians. So if you want to make turn of 90 degrees, you have to recalculate the degree value to radians.
This can be done by mathutils, i guess. Or you build a small function dooing this.
I dont think it is possible to do this with motion actuator.
Another way to do it, is using a ipo curve, turning 360 degrees.
If you then use a Ipo-Actuator with property, you can just give the Property the value you need.

Let’s say you have a turret that you want to rotate with an analogue stick. You might convert the values from the stick to give your turret cover 90’ left and 90’ right. But you don’t want the turret to spin wildly. So if you are using rotation in you script to do the job set the rotation to zero at the beginning of the script. So at the beginning of the script it’s zero and three or four lines later it’s 45 or 46 or 47 or whatever giving a nice smooth motion.

If you are using the keyboard, Left arrow might start a counter from one to 180 back to one and so on, over three seconds. Give that value to your script but in the previous line set rotation to zero.

Or instead of a counter you can use the system time and make an accurate sweep second hand for a watch.

controlledRotation.blend (446 KB)

It’s a while since I’ve posted a blend. Looks like it’s gonna work.

To rotate 90 degrees using applyRotation:

from math import pi

import bge

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

Thanks andrew for “import pi”. I’ve been using a float to 12 decimal places. Prior to that I didn’t know what was going on because I thought that since I had degrees selected for actuators that everything would be alright.