Mouselook that only rotates left and right

Hey, does anyone have a very simple script that is a mouselook but only rotates left or right? Kinda like the generic one, but doesn’t have the UpDown.

Thank you! It works pretty well. I know that it’s kinda irrelevant, but could you explain me the script bit by bit? I just want to learn more.

x, y = bge.logic.mouse.position

x and y here the coordinate (orizontal and vertical) of the mouse in the screen , this can be a number from 0 to 1
0,0 is left , top
1,0 is right, top
0,1 is left bottom
1,1 is right bottom

  • 0.5
    is to “semplify the calculation” , so , if the mouse is in the center of screen return => x=0.5 , y= 0.5
    … is more simple instead have => 0.0 , 0.0

abs mean “absolute” (is a function of python)
this clean the sign -/+ and return ever positive
ex:
abs(-0.6) ===> 0.6
abs(+0.6) ===> 0.6

0.01 is a kind of filter to avoid the “continue turn” (little inaccurancy think from the float number, but not sure)

:wink:

to rotate only left right , seem to me not necessary the “init line”
very short :slight_smile:


import bge 

own = bge.logic.getCurrentController().owner

x = 0.5 - bge.logic.mouse.position[0]

if abs(x) > 0.01 :
    own.applyRotation((0.0, 0.0, x), 0) 

bge.logic.mouse.position = 0.5,0.5 


PS:
bge.logic.mouse.position = 0.5,0.5 ###yes this work to replace the mouse to the center of screen :wink:

also 0.01 can be a bit huge, maybe is better a number a bit too little

A great tutorial from Goran: (Don’t know how I forgot this!)