How do I make a controls rebind system?

0 favourites
  • 4 posts
From the Asset Store
Have you tried to create realistic and at the same time casual tank movements? You found the perfect solution!
  • In most game engines, there's typically a system to create key/action mappings like:

    {
    	"jump": "Spacebar" | "Gamepad A",
    	"interact": "E" | "Gamepad B"
    }
    

    This allows developers to reference actions like "jump" in the code, instead of hardcoding specific key presses, and easily modify key bindings at runtime so players can remap controls as they prefer.

    However, it seems that Construct 3 doesn't have a built-in system like this, which seems a little weird to me.

    Is there currently a way to achieve this functionality in Construct 3?

    Thanks!

    Tagged:

  • I agree, this is an absolute headache to do in Construct - and something that would be great if the engine did more of the heavy lifting with. It can be done with a combination of variables, local storage and key codes - setting it up is a total creativity killer. I've been learning a bit of Godot recently and I was flabbergasted at how easy it was to set up in comparison!

    Here's one example of how it can be done in C3 that I think helped me: https://www.youtube.com/watch?v=bkdOdAX2mrA

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • i did this by making a dictionary for gameKeys and gameActions, and then at the top of my main event sheet have a giant bundle of or block events that check if a keyboard or gamepad is pushing one of the relevant buttons:

    when the game starts as part of my init function it loads all the default gameKeys from a dictionary project file, but you can change the key codes at runtime by using the LastKeyCode expression. i haven't actually implemented this yet because i'm not sure of the UI, so i don't have an example to share, sorry about that!

    so all "on key press" actions are replaced with "if gameActions key 'down' is 1" and all "key is down" actions are replaced with "if gameActions key 'down' >= 1" and such.

    (these r collapsed)

    this also meant i could keep track of how many frames each key has been down, which i used to implement DAS or auto-repeat with this function:

    i also frequently add 1 to the relevant gameActions if, for instance, you're in the menu and push "confirm" so that it doesn't automatically confirm when the next window opens as well

    i'm actually pretty proud of this one (i love that i was able to implement auto-repeat like that tbh) but i do agree it was kind of a bummer it was so roundabout. i hope my code helps, lmk if you need clarification!

  • Thank you very much for the help, guys!

    Very cool system, paxclara. Probably i will go this way too for now.

    For the Construct team: C3 is AWESOME, but i think this is some of the most basic needs of every game developer. The input and rebind system of a game need to be robust. It would be so good if you guys could add this in a future update!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)