I’m currently using this scrip for my camera control but how do I limit its control when I view up or down? When I move my mouse up or down, it would rotate one full rotation.
MouseLook.py Blender 3D 2.43
Clark Thames
#################### Quick Instructions ########################
The python script is attached to the Camera Controller
It is used to rotate both the camera and the player
Buttons Window Menu >> Logic(F4) panel
In 3D View Window, select camera and player
(Logic panel will show both at same time)
Add Mouse sensor and Python script controller to Camera
Add a Motion Actuator to Camera
Add a Motion Actuator to Player
Connect the Camera python script to Camera actuator AND Player actuator
#################################################################
############ Variables you might want to change ################
MOUSE SENSITIVITY
sensitivity = 0.004
DIRECTION MOUSE LOOK MOVES
Use either 1 or -1 (Minus one will flip the direction.)
directionLeftRight = -1
directionUpDown = 1
############## Import the python game modules ###################
Load the GameLogic Module
import GameLogic
Import the Rasterizer Module (game window functions)
import Rasterizer
############# Get the controllers and sensors #################
Get controller you attached this python script to
controller = GameLogic.getCurrentController()
Get mouse sensor you added to same controller
mouse = controller.getSensor(“Mouse”)
############# Get size of game window ###############
Get game window height and width
gameWidth = Rasterizer.getWindowWidth()
gameHeight = Rasterizer.getWindowHeight()
################## Get amount mouse moved #######################
Get the mouse movement
def mouseMove():
x = mouse.getXPosition() - gameWidth/2
y = mouse.getYPosition() - gameHeight/2
# First time mouse look will 'jerk'
# Don't want that
if hasattr(GameLogic, 'init') == False:
x = 0
y = 0
GameLogic.init = True
return (x, y)
pos = mouseMove()
######## Figure out how much to rotate camera and player ########
Amount, direction and sensitivity
rotLeftRight = (pos[0] * directionLeftRight) * sensitivity
rotUpDown = (pos[1] * directionUpDown) * sensitivity
######### Use actuators to rotate camera and player #############
Get the actuators
leftRight = controller.getActuator(“LookLeftRight”)
upDown = controller.getActuator(“LookUpDown”)
Set the rotation values
leftRight.setDRot( 0.0, 0.0, rotLeftRight, False)
upDown.setDRot( rotUpDown, 0.0, 0.0, True)
Use them
GameLogic.addActiveActuator(leftRight, True)
GameLogic.addActiveActuator(upDown, True)
############# Center mouse pointer in game window ###############
Center mouse in game window
Rasterizer.setMousePosition(gameWidth/2, gameHeight/2)