Mouse Look with Constraints?

I’m currently attempting to convert an old script I had for use with 2.57, but haven’t had much luck in getting it to work so far. I need a mouse look script which can be constrained in both the x and y dimensions. Does anyone have such a script? The current one I have looks like this:

    from bge import logic as g
    from bge import events
    from bge import render as r

    c = g.getCurrentController()
    o = c.owner

    from math import sin, cos
    import mathutils

    if (g.InGame == 1 or g.InGame == 2):

        midx = r.getWindowWidth()/2
        midy = r.getWindowHeight()/2

        r.setMousePosition(int(midx), int(midy))

        mouse = c.sensors['Move']

        if o['ago'] < 0.0:

            r.setMousePosition(int(r.getWindowWidth()/2), int(r.getWindowHeight()/2))

            deltax = 0
            deltay = 0


            deltax = midx - mouse.position[0]
            deltay = midy - mouse.position[1]

        dt = o['now'] - o['ago']
        o['ago'] = o['now']

        osz = o['sz'] # Z Axis Rotation
        ocz = o['cz']
        zrot = (3.141592654 * -1 * g.MouseSens) * dt* deltax
        szrot = sin(zrot)
        czrot = cos(zrot)
        o['cz'] = -osz*szrot + ocz*czrot
        o['sz'] =  osz*czrot + ocz*szrot

        osx = o['sx'] # X Axis Rotation
        ocx = o['cx']
        xrot = (3.141592654 * g.MouseInvert * g.MouseSens) * dt* deltay
        sxrot = sin(xrot)
        cxrot = cos(xrot)
        o['cx'] = -osx*sxrot + ocx*cxrot
        o['sx'] =  osx*cxrot + ocx*sxrot

        if o['cx'] < 0.7: # Up/Down Constraint

            o['cx'] = ocx
            o['sx'] = osx

        if o['cz'] < 0.5: # Left/Right Constraint

            o['cz'] = ocz
            o['sz'] = osz

        o.localOrientation([ \
            [  o['cz'], o['sz']*o['cx'], o['sz']*o['sx'] ], \
            [ -o['sz'], o['cz']*o['cx'], o['cz']*o['sx'] ], \
            [        0,        -o['sx'],         o['cx'] ] ] )

Far from the simplest out there I know…

Current error when I try run this is:

TypeError: ‘mathutils.Matrix’ object is not callable

Any ideas what this means and how it can be fixed?

localOrientation isn’t a function
try this:

o.localOrientation = [ \
            [  o['cz'], o['sz']*o['cx'], o['sz']*o['sx'] ], \
            [ -o['sz'], o['cz']*o['cx'], o['cz']*o['sx'] ], \
            [        0,        -o['sx'],         o['cx'] ] ]

What is your prob exactly? Do you want a cap so that you can only rotate the cam within a certain sweep? If so, the easiest way is to record the yaw and pitch of your cam in properties and check them each frame against the cap angle you want.

Thought it might be something simple like that, still getting used to the new python API. That’s got it working again, thanks.

That’s basically what I need, to only be able to rotate the camera through a restricted angle rather than the full 360 degrees. This script basically does that, though it can probably be simplified a little.

Just an issue with it drifting now, noticed quite a few of the other mouse look scripts have that issue. Know what the cause is?

I don’t know the cause, but I just add a minimum value that the mouse’s X or Y movement values need to exceed (like 0.002 or something like that).