Add Cap to Mouslook script 2.49

Here is my mouselook script (2.49). How would I go about adding a “Cap” to the script, so that its verticle axis is constrained?

import Rasterizer

import Rasterizer

get controller

controller = GameLogic.getCurrentController()

get the object this script is attached to

player = controller.getOwner()

Get sensor named Mouse

mouse = controller.getSensor(“Mouse”)

Get the actuators

lookLeftRight = controller.getActuator(“LookLeftRight”)
lookUpDown = controller.getActuator(“LookUpDown”)

get width and height of game window

width = Rasterizer.getWindowWidth()
height = Rasterizer.getWindowHeight()

define mouse movement function

def mouseMove():

# distance moved from screen center      
x = width/2 - mouse.getXPosition()
y = height/2 - mouse.getYPosition()
# intialize mouse so it doesn't jerk first time
if hasattr(player, 'mouseInit') == False:
    x = 0
    y = 0
    # bug in Add Property
    # can't use True.  Have to use 1
    player.mouseInit = 1
# return mouse movement
return (x, y)

get mouse movement from function

move = mouseMove()

set mouse sensitivity

sensitivity = 0.0005

Amount, direction and sensitivity

leftRight = move[0] * sensitivity
upDown = move[1] * sensitivity

set the values

lookLeftRight.setDRot( 0.0, 0.0, leftRight, False)
lookUpDown.setDRot( upDown, 0.0, 0.0, True)

Use them

GameLogic.addActiveActuator(lookLeftRight, True)
GameLogic.addActiveActuator(lookUpDown, True)

Center mouse in game window

Rasterizer.setMousePosition(width/2, height/2)

i had a similar problem the other day and solved it this way:

x_rot = bge.getCurrentController().owner.localOrientation.to_euler()[0]/(math.pi/2)*90

no idea if this works in 2.49 since they chanced the api (which might have been before 2.49?) but in 2.6. x_rot gives you the rotation around the local x-axis which youd be able to constrain between 90 and -90. then again, theres the constraint actuator that ive never used before but maybe that does the trick…

Use a ContraintActuator in orientation mode.

The above code just set the parameter of the motion actuator. It does not care the current orientation of the object.

Next time please suround code with code tags