How to configure the game controls?

I would like to know how I can customize the controls of my game, without being too simple, like the game below:


I would like to configure the way I want, as this well-known game below:

I also want to use both the joystick as the keyboard has someone help me?

Python scripting, no way around.

You certainly already have your own keyboard sensors already, these should represent “high level actions”.

What I mean is your sensor shouldn’t be named “W” for the “W” key, but maybe “Forward”. You would do that for most actions in your game where you need a button to trigger the action.

Then you need a Python script that would allow you to edit the keys your sensors are listening to while your game is running. I can only recommend to start learning basics of Python and how to edit the sensor’s configuration.

Because if you want to be able to configure game controls, you will have to write that logic yourself :slight_smile:

BGE Python basics: https://docs.blender.org/api/2.79/bge.logic.html
Keyboard sensor API: https://docs.blender.org/api/2.79/bge.types.SCA_KeyboardSensor.html#bge.types.SCA_KeyboardSensor

I’m seeing it will be difficult :inexpressivo:

Depends on what you call difficult. It can be done if you actually commit to it, but yes it may take some thinking and learning how to code a bit.

why don’t you use the search function instead of asking for everything, all you need is already made available by someone

Not necessarily, you can have pre-defined controsl that are switched depending on a game-property.

This is obviously not a dynamic approach :wink:

Is there no template to use for a control pad, what control pad can be used? USB type one? I have one myself only the direction buttons work and a number of others so x, circle, square and triangle, like an old PS2 control pad.

I have used these controllers & they work fine -

(Original) Xbox 360 controllers (2x)
(Logitech) PS3 controller

All controllers should work with BGE / UPBGE joystick inputs (Logic_Brick or Python)
There really isn’t a guide to all the joystick input numbers, their all different in someway.

There is one major bug tho (it might be fixed in UPBGE)
The bug is joystick input not being received by Blender when game is played in the 3D View-Port.
Joysticks always work fine in Blenderplayer tho.

Hmm, since I use the game engine, upbge won’t apply to this, and doesn’t make much difference, I guess.

If I try the USB control pad, I then need to use joystick brick? How do know which button the pad does what?

bge.logic.joysticks gives you a list of slots each containing a joystick object if one is available at that index else none. At init, I run a loop over it like so to get whichever slot I got mine plugged into.

from bge.logic import joysticks

joy_index = -1
for i, stick in enumerate(joysticks):
    if stick:
        joy_index = i
        break

joy = joysticks[joy_index]

Now that you have a reference to the thing, you can get a list of indexes for pressed buttons. Print it to console, it spits out a number from 0 to number of buttons on your joystick. This integer represents that button, you can use it to check for that particular input.

butts = joy.activeButtons
if butts:
    print(butts)
    if 0 in butts: print("X on a ps2 controller")

Then you just write down which one is which or whatever.

Unavoidable pain in the arse as it is, you’re gonna have a hard time doing this kind of thing without any programming knowledge.

I haven’t been very successful with the game engine, I wanted to do more than I have, I was lucky to get some help from a number of users here, who helped me out with programming, and brick programming.

I guess, the first step is to get one button to move a character. At the most, I would need perhaps four buttons. If it is possible to close the game, then five. One button would be for an alterntive camera view.

A current file I am messing with not related to my released couple of files, may require some kind of camera change or targeting system, otherwise the FP can’t see the AI, or much.

bge.logic import joysticks

joy_index = -1
for i, stick in enumerate(joysticks):
if stick:
joy_index = i
break

joy = joysticks[joy_index]

butts = joy.activeButtons
if butts:
print(butts)
if 0 in butts: print(“X on a ps2 controller”)

What is butts? That is some keyword given.

joy.activeButtons is a list of active inputs. Here I’m just assigning it the name butts and totally not what you think, it’s just short for buttons.

I will need a little more of an example.:confused:

if joy.activeButtons: #the list has values; i.e. it's not empty
     if 0 in joy.activeButtons: #joystick button nº 0 is pressed
          #put your logic for this button press here
     if 1 in joy.activeButtons: #joystick button nº 1 is pressed
          #same as before

And so on, up to total number of buttons on your pad.

@modelinblender

I forgot to mention there is a build-in joysticks program for Windows computers.
It’s called Set up USB game controllers .

It tells you the connect & selected joystick’s Button numbers, Hat numbers, Axis values.

Be warned Blender sometimes mixes up the joystick numbers (meaning you sometimes won’t get the right input number.