I have this MouseLook script, and i want use it as a normal script, not Module.

Here the script:

from bge import render
from mathutils import Vector
from math import pi

CAP = (pi/2)-0.1

def get_window():
    return (render.getWindowWidth(), render.getWindowHeight())

def get_window_center():
    window = get_window()
    return (window[0]//2, window[1]//2)

def center_mouse():
    center = get_window_center()

def look(cont):
    own = cont.owner
    m = cont.sensors['Mouse']
    head = own.children['Tete']

    sensitivity = own['Sensibilite']*0.001
    smooth = own['Smooth']

    if 'oldX' not in own:
        center = get_window_center()
        own['oldX'] = center[0]
        own['oldY'] = center[1]
        source = Vector(get_window_center())
        mpos = Vector(m.position)

        x = source.x - mpos.x
        y = source.y - mpos.y

        own['oldX'] = own['oldX'] * smooth + x * (1.0-smooth)
        own['oldY'] = own['oldY'] * smooth + y * (1.0-smooth)

        x = own['oldX'] * sensitivity
        y = own['oldY'] * sensitivity*(render.getWindowHeight() / render.getWindowWidth())

        own.applyRotation([0,0,x], False)
        head.applyRotation([y,0,0], True)

        ori = head.localOrientation.to_euler()
        if ori.x <= -CAP:
            ori.x = -CAP
        elif ori.x >= CAP:
            ori.x = CAP
        head.localOrientation = ori


I actually use a Module python controller (Mouselook.look).

  • $\begingroup$ I solved my answer $\endgroup$ – Hack0re Nov 11 '15 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.