Game Development Community

Creating button combos?

by Tom Biagioni · in Torque Game Builder · 09/11/2006 (5:48 pm) · 7 replies

I was curious how i would create a multi-key combonation?

like say i have u assigned to a low punch, and i assigned to a high punch, and wanted u + i to equal a fierce or something like that. im am totally clueless on how to implement this kind of function since i'm still fairly new to scripting and torque in general.

any help is greatly appreciated.

#1
09/12/2006 (3:43 pm)
I'd be curious about this too if anyone has any tips.
#2
09/12/2006 (3:53 pm)
You could set a variables such as $lowpunch = true and $highpunch = true as the character pulls off each move. You would then have a checkCombo function that was basically: if ($lowpunch && $highpunch) activateFiercePunch();

Something like that anyway :)
#3
09/12/2006 (3:59 pm)
Most combo systems in games are based on timing which means you need to put some sort of inherent delay into the system.

I would create some sort of combo watcher object. It would receive inputs from the function callbacks like you normally would use. The combo watcher would have to issue immediate or scheduled calls to actions to perform. If a second input comes within a fixed time period or before the scheduled action has been executed and that second input constitutes a valid combo, the previous schedule/action is canceled and the new one is fired/scheduled.

I'm sure with a little effort some sort of reusable component could be made of this.
#4
09/12/2006 (4:08 pm)
When I needed a combo type system I used a method similar to what Tom laid out, worked well, but my testing was limited!
#5
09/21/2006 (6:37 pm)
Im unsure how to create this inherent delay for the combo system, can anyone help me out with this one?
#6
09/21/2006 (10:21 pm)
I guess when the user presses a key you would just use a schedule() to call a function which will check if they hit the next combo button by the time that function is called. If so, it schedules that function again to test for the next button in the combo, until either one of the functions fails, or they reach the end of the combo. I'm sure there would even be a smart way to write it so it can work for lots of different input combos.
#7
09/22/2006 (2:51 am)
One way to do it would be with an input queue and a state machine. The queue would have to keep track of the time at each input event and possibly group them. The state machine would be in charge of interpreting that input. So, say, at idle state you hit punch -> punch+kick -> punch. Since the queue most likely won't get the second punch and the kick event at the exact same time, you will have to give it some sort of time threshold, like maybe if two input events occur within a fifth of a second they are deemed 'same-time' input events.

You would first decide if the fighter is in a state to initiate a punch. If so, enter the punching state. Then the state machine would have to decide what to do with punch+kick input while in the punching state. If there is a normal move to be done, you can choose to execute it, or you can throw in a fancy combo-move, or you can choose not to do anything at all if the input was too soon or too late relative to the first punch. The key would be interpreting the time difference in the input. You don't really need to schedule anything, since you can tell how much time has passed since the last input reported from the queue.

That's just one way, I'm sure there are others.