MouseLook script Cap problem

for position you can copy the world.Position from your Player to the camera

but you can use it as an normal script if you delet the def(): line and add the line:
cont = logic.getCurrentController()

than do move the tabs a little and done.

Ok, i just make your script work for me, but the worst hapened:
Your script does the same than the one of TutorialForBlender3D, when i move the mouse rapidly to the cap angle, the cap angle is exceed.(we can see it when print(angle)).
The only script that dont do this is the MouseMove script from Riyuzakisan (The MouseLook system is perfect), but the script is verry complicated, and there is many useless things inside (for me).

Thanks anyway the_cannibal

GOOD fps_rig.blend (676 KB)

Here is the basic FPS rig I’ve been putting together, using a mouselook script I’ve been using quite a bit lately. It’s a revision of an old script by Mr Mike Pan, I just changed the depricated language, and took advantage of some things that probably weren’t available at the time of the original script’s writing.

To use, make sure your player object’s body has a child named Head (placed where your character’s head is). Parent your camera to the head. On the body, use a Mouse Movement sensor (no positive pulse!) and noodle it to a python controller, module mode, running fps.look.
The body needs two float properties as variables in the script: ‘mouse_sensitivity’ and ‘mouse_smooth’. The cap is defined as a global at the top of the script (and measured in radians, the value given in that file is a bit under 90 degrees up and down).

NOTE that if you edit out the movement code in that script (which I wouldn’t blame you…it’s not very good yet), mouselook requires the three methods at the top of the file to work: get_window(), get_window_center(), and center_mouse(). Make sure you preserve those :wink:

Nines, did you take a look at my rig? :smiley:

Yeah, it’s pretty sweet!

know what you mean but don’t no how to solve this. Riyuzakisan script is really nice but in the self section of Python I am not the best, sorry

Thank you guys, but i search a simple script(all in one script), i dont want to use more than 2 logic bricks Sensors for it, and only one python controller in “script”, not module…
I dont need a rotating head, i just need a simple camera parented to my player on character physics.
Thank you anyway.

parent the camera to the head, set the head invisible, now it does what you want.

about the sensors… why?

it works, and would be hassle free, and is 100% less complicated, meaning you may actually be able to edit it to do what you want…

you are beating a dead horse.

i need all this inside one script.

You don’t explain the why.

and it’s actually pretty easy to mix those two scripts…

@@Lyricorp, I don’t know how to work with matrices so I use the following code to cap the mouselook


if camOri.to_euler().x > 2.9:
    offset.y = 0
    rot = camOri.to_euler()
    rot.x = 2.89
    ori_to = rot.to_matrix().copy()
    camera.localOrientation = camera.localOrientation.lerp(ori_to,0.1)
        
elif camOri.to_euler().x < 0.5:
    offset.y = 0
    rot = camOri.to_euler()
    rot.x = 0.51
    ori_to = rot.to_matrix().copy()
    camera.localOrientation = camera.localOrientation.lerp(ori_to,0.1)

Test_fix.blend (513 KB)

I have changed the code and added mouse y position into the code for verification, also adjusted the speed of the offset value so the game doesn’t freak out when you’re moving it back and forth


    mYpos = mouse.position[1] - y
    if math.degrees(camOri.to_euler().x) > capHaut:
        offset.y *= 0.001
        rot = camOri.to_euler()
        rot.x = math.radians(capHaut)
        ori_to = rot.to_matrix()
        camera.localOrientation = camera.localOrientation.lerp(ori_to,1)
        if mYpos < 0:
            offset.y = 0
        
    elif math.degrees(camOri.to_euler().x) < capBas:
        offset.y *= 0.001
        rot = camOri.to_euler()
        rot.x = math.radians(capBas)
        ori_to = rot.to_matrix()
        camera.localOrientation = camera.localOrientation.lerp(ori_to,1)
        if mYpos < 0:
            offset.y = 0
    else:
        offset.y *= 0.3

    camera.applyRotation((offset.y, 0, 0), True)

Test_fix2.blend (545 KB)

it seems to work great, i just have to add the left-right rotation.
Thanks dude.
edit: when i change the cap angle, there is the same issue than before.

hi a little massive late but,

today have figured out this and it is working really good:


def main(cont):
    own = cont.owner
    scene = logic.getCurrentScene()
    cameraTarget = scene.objects["cameraTarget"]
    mouse = cont.sensors["Mouse"]
    
    movSpeed = 0.3
    rotSpeed = (0.005, 0.005)
    S = 0.8
    cap_top = -200
    cap_buttom = 60
    
    # mouse look
    x = (render.getWindowWidth() / 2 - mouse.position[0])
    y = (render.getWindowHeight() / 2 - mouse.position[1])
    
    # mouse smooth
    own['oldX'] = (own['oldX']*S + x*(1-S))
    own['oldY'] = (own['oldY']*S + y*(1-S))
    x = own['oldX']
    y = own['oldY']

    own['x'] += x
    own['y'] += y

    #sniped from other code
    #if own['x'] >= 1440:
    #    own['x'] = 0
    
    # cap mouse look
    if cap_buttom > own['y'] > cap_top:
        cameraTarget.applyRotation((int(y) * rotSpeed[0], 0, 0), True)
    if own['y'] <= cap_top:
        own['y'] = cap_top+1
    if own['y'] >= cap_buttom:
        own['y'] = cap_buttom-1
   
    # apply player rotation and center mouse
    own.applyRotation((0 , 0, int(x) * rotSpeed[0]), True)
    render.setMousePosition(int(render.getWindowWidth() / 2), int(render.getWindowHeight() / 2))