Mouse look bug

import bge


logic = bge.logic
mouse = logic.mouse


### CAMERA ###
def cam_orbit(cont):
    own = cont.owner
    scene = own.scene
    target = scene.objects[own["target"]]
    trackToTarget = cont.actuators["trackToTarget"]
    trackToTarget.object = target
    cont.activate(trackToTarget)
    
    if not "oldCursorPosition" in own:
        own["oldCursorPosition"] = [0.5, 0.5]
        mouse.position = (0.5, 0.5)
        
    x = (0.5 - mouse.position[0]) * own["sensitivity"]
    y = (0.5 - mouse.position[1]) * own["sensitivity"]
    
    deltaX = x
    deltaY = y
    
    target.applyRotation([-deltaY, 0, 0], True)
    target.applyRotation([0, 0, deltaX], False)
    
    mouse.position = (0.5, 0.5)

I’ve made this basic code. It’s supposed to work as mouse look orbit script. It works, but there is a massive problem. The object is rotating like if mouse was slightly down(e.g. like if it was 0.499), even though it’s at 0.5. I tried adjusting numbers up(like so: 0.50130519 or similar), but either the object kept rotating upwards, or started rotating downards, but it never stands still. What’s the reason of this issue and how to fix it?

0.499 might be 0.5 with loss of accuracy? Maybe if you create a buffer zone in the middle of the screen between 0.45 and 0.55 for both x and y coordinates, the mouse can rest there without affecting movement. Do this with:


if not mouse.position[0] > 0.45 and not mouse.position[0] < 0.55:
    if not mouse.position[1] > 0.45 and not mouse.position[1] < 0.55:

         target.applyRotation([-deltaY, 0, 0], True)
         target.applyRotation([0, 0, deltaX], False)
    

Thanks. Of course, 0.45 and 0.55 is overkill. The error is like 0.004 or something like that(not exact). I found that 0.505 and 0.495 is totally enaugh. Also, it’s working well for x axis and only y axis needs this error removal range.

Problem solved!:slight_smile: