Controller support

Hello, I want to add xinput controller support for my game but still want to keep the keyboard as well.
Also i want the controller input to be dynamic.
So if the digital keyboard input value of a rotation is let’s say 50, I want the controller input to build up to the 50 depending on how much you turn the stick.
Is there a tutorial, example file or resource for this?
Thanks in advance for any help!

Yup, 100% possible. Using a joystick does not in any way exclude usage of the keyboard, so you can use both as inputs for your game.
As for “dynamic input” from the controller, a simple script will allow you to get the information from the joystick.

import bge

def main():

    cont = bge.logic.getCurrentController()
    own = cont.owner

    # Get the joystick sensor that is hooked to this controller
    sens = cont.sensors['Joystick']

    # If the joystick is being pushed...
    if sens.positive:

        # …get how hard the joystick is being pushed...
        x = sens.axisValues[2] # I don't know what kind of variations there are in controllers,
        # but axis "2"  is left and right using my right joystick.

        # …and add it to the object's rotation. (Object should be dynamic)
        try:
            own.setAngularVelocity((0.0, 0.0, x/20000) ) # Edit: Fixed an error.
            # This number "20000" is what you could use to set the max rotation speed.
            # own.localOrientaion += (0.0, 0.0, x/KeyboardInput) # To use your example.
            # Remember: In this example, the greater "KeyboardInput" is, the slower the object will rotate.

        except ZeroDivisionError:
            pass
    else:
        pass

main()

I hope this example is clear.
Let me know if you need more help.

1 Like

Thanks, hopefully I’ll find some time soon to try it out. I’ll get back to this topic when I’m on it again :slight_smile: