Hey I am new to this stuff as well, but I do have a script here that will help, it has capp, invert and speed.
#####################################################
MouseLook.py Blender 2.49
Tutorial for using MouseLook.py can be found at
######################################################
define main program
def main():
set default values
Sensitivity = 0.00015
Invert = 1
Capped = False
import Rasterizer
import Rasterizer
get controller
controller = GameLogic.getCurrentController()
get the object this script is attached to
obj = controller.owner
get the size of the game screen
gameScreen = gameWindow(Rasterizer)
get mouse movement
move = mouseMove(gameScreen, controller, obj)
change mouse sensitivity?
sensitivity = mouseSen(Sensitivity, obj)
invert mouse pitch?
invert = mousePitch(Invert, obj)
upDown mouse capped?
capped = mouseCap(Capped, move, invert, obj)
use mouse look
useMouseLook(controller, capped, move, invert, sensitivity)
Center mouse in game window
centerCursor(gameScreen, Rasterizer)
#####################################################
define game window
def gameWindow(Rasterizer):
get width and height of game window
width = Rasterizer.getWindowWidth()
height = Rasterizer.getWindowHeight()
return (width, height)
#######################################################
define mouse movement function
def mouseMove(gameScreen, controller, obj):
Get sensor named MouseLook
sen_mouse = controller.sensors[“MouseLook”]
extract width and height from gameScreen
width = gameScreen[0]
height = gameScreen[1]
distance moved from screen center
x = width/2 - sen_mouse.position[0]
y = height/2 - sen_mouse.position[1]
intialize mouse so it doesn’t jerk first time
if obj.has_key(‘mouseInit’) == False:
obj[‘mouseInit’] = True
x = 0
y = 0
return mouse movement
return (x, y)
######################################################
define Mouse Sensitivity
def mouseSen(sensitivity, obj):
check so see if property named Adjust was added
if obj.has_key(‘Adjust’) == True:
Don’t want Negative values
if obj[‘Adjust’] < 0.0:
obj[‘Adjust’] = 0.0
adjust the sensitivity
sensitivity = obj[‘Adjust’] * sensitivity
return sensitivity
return sensitivity
#########################################################
define Invert mouse pitch
def mousePitch(invert, obj):
check to see if property named Invert was added
if obj.has_key(‘Invert’) == True:
pitch to be inverted?
if obj[‘Invert’] == True:
invert = -1
else:
invert = 1
return mouse pitch
return invert
#####################################################
define Cap vertical mouselook
def mouseCap(capped, move, invert, obj):
check to see if property named Cap was added
if obj.has_key(‘Cap’) == True:
import mathutils
import Mathutils
limit cap to 0 - 180 degrees
if obj[‘Cap’] > 180:
obj[‘Cap’] = 180
if obj[‘Cap’] < 0:
obj[‘Cap’] = 0
get the orientation of the camera to world axis
camOrient = obj.orientation
get camera Z axis vector
camZ = camOrient[2]
create camera z axis vector
vec1 = Mathutils.Vector(camZ)
get camera parent
camParent = obj.parent
get parent orientation to world axis
parentOrient = camParent.orientation
get parent z axis vector
parentZ = parentOrient[2]
create parent z axis vector
vec2 = Mathutils.Vector(parentZ)
find angle between two
angle = Mathutils.AngleBetweenVecs(vec1, vec2)
get amount to limit mouselook
capAngle = obj[‘Cap’]
get mouse up down movement
moveY = move[1] * invert
check capped angle against against camera z-axis and mouse y movement
if (angle > (90 + capAngle/2) and moveY > 0) or (angle < (90 - capAngle/2) and moveY < 0) == True:
no movement
capped = True
return capped
return capped
###############################################
define useMouseLook
def useMouseLook(controller, capped, move, invert, sensitivity):
get up/down movement
if capped == True:
upDown = 0
else:
upDown = move[1] * sensitivity * invert
get left/right movement
leftRight = move[0] * sensitivity * invert
Get the actuators
act_LeftRight = controller.actuators[“LeftRight”]
act_UpDown = controller.actuators[“UpDown”]
set the values
act_LeftRight.dRot = [ 0.0, 0.0, leftRight]
act_LeftRight.useLocalDRot = False
act_UpDown.dRot = [ upDown, 0.0, 0.0]
act_UpDown.useLocalDRot = True
Use the actuators
controller.activate(act_LeftRight)
controller.activate(act_UpDown)
#############################################
define center mouse cursor
def centerCursor(gameScreen, Rasterizer):
extract width and height from gameScreen
width = gameScreen[0]
height = gameScreen[1]
Center mouse in game window
Rasterizer.setMousePosition(width/2, height/2)
##############################################
Run program
main()
Ok now for it to work, open text editor, paste the script in it, next select the camera you want to use, go into game logic, add Mouse senser, python controller, and motion actuator, Name the sensor "MouseLook" ( Be sure to capitolize, and no spacing) set the sensor to movement. And the name of my script is "MouseLook.py". So in the python controller write the name of your script. It the motion actuator name it "UpDown". Now parent your camera to your player and select both, give you player a motion actuator, and call it "LeftRight", conect all of these, and move your camera behind your player and press play, it should work, but I am using Blender 2.49. If you want to put a cap on it select the camera, add "int" property name it "Cap", and put on 130, or whatever suites you. If you want to change the speed of your turn then add a "Float" property and name it "Adjust" , set it to 4.000 or something, but play around with. And if you want Invert, Add a "Bool" actuator and name it "Invert", set it to true. And I think this should all work, I will check on this again, so if you have anymore qustions just replay on this, and I will try to help, see you around.