I want to orbit the camera using a script without centering the cursor. So I wrote this script:

import bge

# get this controller script
cont = bge.logic.getCurrentController()
# get sensor named MouseLook
mouse = cont.sensors['MouseLook']
mousePosX = mouse.position[0]
mousePosY = mouse.position[1]
# get old mouse coords
obj = cont.owner
if not 'mousePosOldX' in obj:
    obj['mousePosOldX'] = 0
    obj['mousePosOldY'] = 0

# velocity
velX = mousePosX-obj['mousePosOldX']
velY = mousePosY-obj['mousePosOldY']
# get the actuators
moveH = cont.actuators['MoveH']
moveV = cont.actuators['MoveV']
# apply movement
moveH.dRot = [0, 0, velX*10]
moveV.dRot = [velY*10, 0, 0]
print('velX: {0}, velY: {1}' .format(velX, velY))

# save old pos in obj properties
obj['mousePosOldX'] = mousePosX
obj['mousePosOldY'] = mousePosY

Using this setup:


And this game logic:

enter image description here

Unfortunately, nothing moves! The script seems to work, because I get valid values in the console from the print. When I directly connect the Sensor to the actuator without the script, the movement is applied (of course just with these constant values, which I don't want). So script alone works, and the movement along works too, where is the bug?


Ah, found it. Apparently, one have to add:


to actually apply the motion

  • $\begingroup$ Please accept your own answer.. $\endgroup$ – WhatAMesh Aug 9 '18 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.