Third Person Mouse-Look Script Help

Hello Blender Community! –
I’m attempting to learn python for Blender’s Game Engine, and as a test of my abilities I am trying to write a Third-Person Mouse-Look Script, as the title suggests. Yet I have run into a roadblock. Everything is working perfectly except for the fact that when I stop moving the mouse, the character keeps on rotating, causing the camera that’s parented to it to keep rotating. I’ve made several attempts at trying to fix this, but nothing has worked. Would anyone take a look at my .blend and suggest a solution? Thanks!

The link to the blend is:

Hi Falcro,
Im no expert in this, but i had a look at the blend and found the problem.
-you need to deactivate the actuator.
when actuators are “activated” they will keep affecting the object until deactivated, so obviously it picked up the mouse move and started turning, but you did not tell it when to stop.
Here is a quick fix i found, replace the second “if” statement with “elif”, since “x<width/2” and “x>width/2” cant happen at the same time so they can be linked into one “if” statement. Then add an “else” clause that deactivates the actuator:

if x > width/2:
rotate.dRot = [0.0, 0.0, -0.01 * (x - width/2)]
elif x < width/2:
rotate.dRot = [0.0, 0.0, 0.01 * (width/2 - x)]

from memory it is know to cause problems when activate and deactivate are both called in the same script eg:
this will actually result in “activate”…dont know why…=_="
so thats why you need to put activate and deactivate in a single if statement so only one gets run.

Happy Coding~