FreeLook help

I’m trying to make a mouse look script, and I’m having problems having the camera stop once it reaches a certain rotation. Some times the camera will stop before it’s meant to, and other times it just doesn’t stop.

Here’s what I’ve made so far. Attach the script to a camera, with a mouse movement sensor, and two movement actuators. There also has to be a property named Cap attached to the camera to set a cap limit.

cont = GameLogic.getCurrentController()
own = cont.owner

import Rasterizer
from Mathutils import *

LeftRight = 0; UpDown = 0

# Finds the center
width = Rasterizer.getWindowWidth() / 2
height = Rasterizer.getWindowHeight() / 2

ori = own.worldOrientation
ori = Matrix(ori[0],ori[1],ori[2])

eul = ori.toEuler()

# Sensors

mouse = cont.sensors["mouse"]

# Actuators

Up_Down = cont.actuators["Up_Down"]
Left_Right = cont.actuators["Left_Right"]

# Process

# Set the mouse to the center
Rasterizer.setMousePosition(width, height)

# Finds how much the mouse has moved
x = width - mouse.position[0]
y = height - mouse.position[1]

# Determines the speed at which to rotate
if own.has_key("Adjust"):
    UpDown = y * .0025 * own["Adjust"]
    LeftRight = x * .0025 * own["Adjust"]
else:
    UpDown = y * .0025
    LeftRight = x * .0025
    
# Stops rotation at the Cap value
if own.has_key("Cap") == True:
    if -eul[0] <= own["Cap"]:
        if UpDown < 0:
            UpDown = 0
    elif -eul[1] >= (180 - own["Cap"]):
        if UpDown > 0:
            UpDown = 0
        
# Sets the rotation values
Up_Down.dRot = [UpDown, 0, 0]
Left_Right.dRot = [0, 0, LeftRight]

# Activates the actuators
cont.activate(Up_Down)
cont.activate(Left_Right)

Rasterizer.showMouse(1)

Why not just use the already developed mouse looks?

http://blenderartists.org/forum/showthread.php?t=173464&highlight=raider

If I were to do that, then I would end up asking a similar question about finding an object’s angles, just in a different scenario.