multiple inputs

Hello I’d like to be able to receive multiple inputs for things like animations, AI scripts, etc. For example pressing multiple buttons at once or a sequence of buttons in a correct order I don’t understand how I would phrase this in code (be aware I am not familiar with C# or Boo so Javacript related advice only) thank you in advance.


Let’s say you need the user to push the key:

a b b a

and you do a backflip.

So, you monitor the keys pushed on the update function. You could simply have a string where you do a contains “abba” and if true, then it does so said action, restarts the string, and then you continue.

This is how I’d go about it, but then your string could get pretty long if the user isn’t really doing anything but button mashing the key buttons without any combos…

Check out the Input in the API:

Detecting multiple buttons pressed simultanously is fairly straight-forward, e.g. in the simplest case you could just check Input.GetKey() for all keys in that combo.

Processing real combos gets a bit more involved. I’d probably start with an approach like this:

  • track the buttons pressed with a e.g. queue or array, limited to N entries as you don’t want to track 100s of keypresses
  • for either each or the last key pressed track when it occured so you can e.g. dismiss combos when there are 60 second pauses between presses
  • on new keypresses check against a list of valid combos (i.e. lists of keys) to map them to specific actions
  • reset the list of tracked keypresses on certain occasions (activated combos, other in-game influences like a character taking a hit, above-mentioned timeouts, …)
  • possibly apply more complicated checks for the timings, e.g. you might require some keypresses to occur near the end of a characters action/animation