I wrote a module to rotate the camera with middle mouse button pressed, zoom in/out with wheel up/down and at last push the camera towards the direction of the mouse if the mouse is getting near to the end of the screen.
I want the camera to be a parent to the player that I have only when the rotation is taking place.So I activate/deactivate the parent actuator but a problem or an error occurs.
While the camera moves as the mouse suggests if the mouse reaches the end of the screen (That is before I press middle button once!), after I rotate the camera I can no longer "push" it under the same conditions.
I tried activating/deactivating the parent actuator or set the mode to remove itself.And all this time I was reading the physicsId of the camera to make sure it can move with linear velocity.All the readings were ok,and no errors popped so I do not know why the camera stops moving after I rotate it once.
Here is the blend file with the module inside it : test blend
and below is the script clean,without comments. Can anyone find what I am doing wrong?
import bge
bge.render.showMouse(True)
scene = bge.logic.getCurrentScene()
player = scene.objects["player"]
cont = bge.logic.getCurrentController()
wh_up = cont.sensors["wh_up"]
wh_down = cont.sensors["wh_down"]
wh_pressed = cont.sensors["wh_pressed"]
par_to_player = cont.actuators["par_to_player"]
cam = scene.active_camera
mousePos = bge.logic.mouse.position
if not wh_pressed.positive:
par_to_player.mode = 2
mX = max(0.0,min(1.0,mousePos[0]))
mY = max(0.0,min(1.0,mousePos[1]))
if mX < 0.05:
cam.localLinearVelocity.x = -5*(2-mX)
cam.localLinearVelocity.y = (0.5-mY)*5
elif mX > 0.95:
cam.localLinearVelocity.x = 5*(2+mX)
cam.localLinearVelocity.y = (0.5-mY)*5
if mY < 0.05:
cam.localLinearVelocity.y = 5*(2+mY)
cam.localLinearVelocity.x = -(0.5-mX)*5
elif mY > 0.95:
cam.localLinearVelocity.y = -5*(2-mY)
cam.localLinearVelocity.x = -(0.5-mX)*5
cam.localLinearVelocity *= 0.9
if (wh_up.positive):
cam.ortho_scale = cam.ortho_scale+5
if (wh_down.positive):
cam.ortho_scale = cam.ortho_scale-5
if (wh_pressed.positive):
bge.render.showMouse(False)
cont.activate(par_to_player)
par_to_player.mode = 1
print (par_to_player.mode)
mX_rot = max(0.0,min(1.0,mousePos[0]))
if (mX_rot < mX):
player.applyRotation([0, 0, -0.01], 0)
elif (mX_rot > mX):
player.applyRotation([0, 0, 0.01], 0)
print ("I reached the end of the module")