Joystick to Mouselook

Hey guys, I was wondering if there was a way to have the right joystick input work with mouselook. For simple First person shooter aiming. Got all other inputs working with their respective keyboard and mouse click equivalents, I just dont know how to get the right stick to use the mouse look actuator. Or maybe someone has a spare script?

Thanks in advance!

It’s certainly simple to do but it’s pretty hacky - you need move the mouse with the joystick since i believe only the mouse will interface with the Mouse actuator when set to Look. You can do this with just an always sensor, python controller with a small script(5 lines), and a mouse look actuator. The problem with this is that any actual mouse movement(the one connected to your computer) will also activate the mouse look actuator.

Even though I don’t recommend using this method or possibly any another method someone may suggest that involves connecting the joystick to a mouse look actuator, I’ll leave the code here so you can decide for yourself.

from bge import logic

cont = logic.getCurrentController()
joy1 = logic.joysticks[0]

logic.mouse.position = logic.mouse.position[0] + joy1.axisValues[3] * 0.05, logic.mouse.position[1] + joy1.axisValues[4] * 0.05
cont.activate(cont.actuators['Mouse'])

The reason I recommend using a different approach is because you can easily achieve the same result as a mouse look actuator with a little more python code(to rotate the object and to simulate the sensitivity and threshold functionality). Or you could connect 4 joystick sensors to 4 motion actuators and do without some of the extra stuff.

If python is the stumbling block for you, I recommend you start learning it. It really isn’t a difficult language. Your game designs will get exponentially better.

Thank you so much for that information and code snippet. I genuinely appreciate it. I tested it and see what you mean. And about python, yeah I definitely need to get started. I’m a graphics and sound guy before programming.

Here is a simplified blend that uses the right stick to rotate the player and pan the camera up and down in a fashion similar to how one would use the mouselook actuator. The only controller I had available was for a PS3 so some alteration may be necessary. I tried to keep the code short and basic.
joystick_look.blend (525.4 KB)

There’s dedicated Joystick stuff in python and its simple.

import bge

size = len(bge.logic.joysticks);
joy  = None;

for index in range(size):
    joy = bge.logic.joysticks[index];

    if joy != None: break;

if joy != None:
    av = joy.axisValues
    btns = joy.activeButtons
    x = av[0]
    y = av[1]

        if av[0] > 0.5 or av[0] < -0.5:
            
            setx = x
        
        if av[1] > 0.5 or av[1] < -0.5:
            
            sety = y


This is just off the top of my head. I’m working on a project that uses full Xbox controller support so feel free to ask fore more. While sodsm_live’s code is clean and elegant it assumes that the curent controller is joy[0] and this isn’t always the case (as i learnt the hard way)

Should you want to add buttons you can use:

if 0 in btns and len(btns) == 1:

With len(btns) == 1 being set to your buttons. (I don’t know all of them just yet)

Note: av[0] and av[1] is left stick x and y, av[3] and av[4] is the right stick.

Hope this helps.

Game engine, how to control moving objects?
The blender manual only states that each controller emits electrical pulses, but we don’t know the most basic, such as how to control an object to move forward and backward and turn.
please help