I’m guessing that applyRotation applies a rotational force to the object? I found a page that said “Rotate the game object a set rotation (works like Motion Actuator Rot)” and another page that says that Motion Actuators set an object into motion. So if that’s the case I would expect it to keep spinning - Newton’s laws… an object continues in its current motion unless acted on by a force.
@others: @Rclub send me a PM, he is still unable to get it working (properly)…
I am no (skilled) python programmer at all but I tried my best by mixing the code of eppo and Rclub:
The script must be aborted by pressing CTRL+C in the console, otherwise it will run forever…
EDIT: My script is horrible. Stick to your concept (use GE) and see my next post…
# rotation function preparations
obj = bpy.data.scenes['Scene'].objects.active
local = False
accel = [0.0]*3
# accelerometer sensor preparations
ser = serial.Serial(port='COM15',baudrate=9600, timeout=1)
# change rot_scale that your accelerometer values rotate
# your object by max. 360 degrees
rot_scale = .0247
def applyRotation(ob, amount, space = False):
ob.rotation_euler[:] = amount
if len(words) >0:
# just for debugging
applyRotation(obj, accel, local)
# main function of the script, REPROGRAM!
time.sleep(0.2) # delay for 0.2 seconds
Since I haven’t your serial input I am unable to test the script…
I Recapitulated your original problem; I think @Kauranga nailed it: applyRotation (probably) adds a constant rotational motion to your object, so you will have to “reset” it (by setting it to 0) when it is applied (otherwise it will rotate forever).
The following code is not ready to run but should clarify my idea (I used your script and added some lines):