Mouselook script for 2.53

Here’s a mouselook script I whipped up in Blender 2.53, And I thought some people might appreciate it. It was developed for the project Snowstorm.

Just put it on a controller on your camera, and attach a mouse movement sensor called ‘MouseMove’. The rest is explained in the script.


"""
MouseLook Script
Written by Mason Bourgeois (Hostage777)
Released under Creative Commons

This script does exactly what it says, controlling
movement of the player's view using the mouse.

Mouselook sensitivity and view inversion can be
controlled through GameLogic variables, which is
useful for changing them through a menu.
Mouselook cap, which controls how far up and down
you can look, can also be contolled through a
global variable.
"""
import bge
#Global Variables w/sample values:
if not hasattr(bge,'mouselook_cap'):
    bge.mouselook_sensitivity = .0005
    bge.mouselook_invert      = False
    bge.mouselook_cap         = 160

c=bge.logic.getCurrentController()
o=c.owner

#mouse sensor
mouse_move=c.sensors['MouseMove']

screen_width=bge.render.getWindowWidth()
screen_height=bge.render.getWindowHeight()
ori=o.orientation

bge.render.setMousePosition(int(screen_width/2),int(screen_height/2))
x=0
y=0

#calculate view movement
x=(int(screen_width/2)-mouse_move.position[0])*bge.mouselook_sensitivity
y=(int(screen_height/2)-mouse_move.position[1])*bge.mouselook_sensitivity

#view inversion
if bge.mouselook_invert:
    y=-y

#mouse cap
if y<0 and ori[2][1]<1 and ori[2][2]>=bge.mouselook_cap/180:
    y=0
elif y>0 and ori[2][1]<1 and ori[2][2]<=-bge.mouselook_cap/180:
    y=0
    
#actually move the camera
if mouse_move.positive:
    o.parent.applyRotation([0.0,0.0,x],1)
    o.applyRotation([y,0.0,0.0],1)

Hope this helps! I tried to make it as user- friendly as possible, because I remember the days as an uber-noob lol.