2
$\begingroup$

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:

-OrbitH
    -OrbitV
        +Camera

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

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

cont.activate(moveH)
cont.activate(moveV)

to actually apply the motion

$\endgroup$
1
  • $\begingroup$ Please accept your own answer.. $\endgroup$
    – WhatAMesh
    Commented Aug 9, 2018 at 14:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .