1
# Example Uses an L{SCA_MouseSensor}, and two L{KX_ObjectActuator}s to implement MouseLook::
2
# To use a mouse movement sensor "Mouse" and a
3
# motion actuator to mouse look:
7
# SCALE sets the speed of motion
10
co = bge.logic.getCurrentController()
12
mouse = co.getSensor("Mouse")
13
lmotion = co.getActuator("LMove")
14
wmotion = co.getActuator("WMove")
16
# Transform the mouse coordinates to see how far the mouse has moved.
18
x = (bge.render.getWindowWidth()/2 - mouse.getXPosition())*SCALE[0]
19
y = (bge.render.getWindowHeight()/2 - mouse.getYPosition())*SCALE[1]
24
# Set the amount of motion: X is applied in world coordinates...
25
lmotion.setTorque(0.0, 0.0, pos[0], False)
26
# ...Y is applied in local coordinates
27
wmotion.setTorque(-pos[1], 0.0, 0.0, True)
29
# Activate both actuators
30
bge.logic.addActiveActuator(lmotion, True)
31
bge.logic.addActiveActuator(wmotion, True)
34
bge.render.setMousePosition(bge.render.getWindowWidth()/2, bge.render.getWindowHeight()/2)