Hey there, its been a while now.
But I’m finally back, though this time not with questions, but with an (hopefully useful) answer!
I figured out how to make a pretty solid combo system using logic bricks that doesn’t require the use of a whole bunch of states and is all glitchy and filled with problems (unlike the ones in tutorials currently available, as far as I’ve seen. Even the python script tutorial has problems).
What this system will use are properties and messengers.
Not only will this allow you to make strings of combos as long as you want (unlike the ones that rely on states, of which there is a limited amount), it doesn’t have the extreme and extensively repetitive hassle of adding a ton of logic bricks in each state for it to work.
So, lets begin!
First the basic set up.
Your character’s mesh should be parented to the bones which animate it.
The character’s bones should in turn be parented to a simple shape which is for the character’s physics (the selected rectangle).
Parented to the physics box is an empty (also selected) which will handle all the key inputs for the combos.
First off, the empty’s logic is as follows:
That’s…quite a bit of logic.
I’ll break it down for you.
Firstly, notice the properties tab. I got one integer named “combo” and a timer named “combo timer” (I know, there’s a third one, but that one isn’t important right now).
The timer will constantly be counting up and will be responsible for timing the combo’s correctly and resetting the “combo” property back to 0.
[ Keyboard sensor - tap ]---------------[ and ]------------------[ Property - add - combo - 1 ]
[ Property - greater than - combo timer ]________________[ Property - assign - combo timer - 0 ]
Both sensors and actuators are connected to the same “and” controller.
The keyboard sensor detects the key press of your choice. What it does is it adds 1 the “combo” property and returns the “combo timer” property back to 0.
The keyboard sensor has the “tap” toggle active. This makes sure the signal gets sent only once to the actuator, regardless if the key is pressed in longer.
The property sensor is there to avoid key spamming. It will only allow the signal of the keyboard be sent if the “combo timer” property is greater than a certain value (something you can assign yourself. The greater the value the longer the time between individual moves will be).
[ Property - equal - combo - 1 ]------------- [ and ]-------------[ message - (your message) ]
The property sensor will detect the value of the “combo” property. If its equal to 1, the sensor will send a message.
You can add as many property sensors you like to create the combo chain, each of them detecting another value of the property “combo” (1, 2, 3 etc) and sending a message (the message can be anything you like, but I suggest you keep it simple. For example “hit 1” for the first move and “hit 2” for the next and so forth).
The message is for the character’s bones, and they’ll detect the messages as follows if you add these logic bricks to the bones:
[ Message - (your message) ]--------------[ and ]--------------------[ Action - play - start frame: xx end frame: xx ]
The message sensor will detect your message from the empty with the combo logic and play the assigned action/animation.
There are a few things you need to make sure of in the action actuator:
For one, you need to make sure that the animation is on “play” and not any of the other options (since its not supposed to be a looping animation).
Another thing is to make sure the actuator’s priority is on a lower value than any other animation priority (the lower the number the higher the priority).
And lastly, this is very important, make sure the “continue” box is not ticked. Keeping this active will make the actuator try to continue the animation where it left off. this means that the action will only play right the first time and not at all the next time.
So, back to the empty with the combo logic.
We still need to close the combo loop, because right now if you keep pressing the attack key it will continue to add values to the “combo” property endlessly.
[ Property - equal - combo - 3 ]------------- [ and ]-------------[ message - (your message) ]
___________________________[ or ] [ property - set - combo - 0 ]
[ Property - greater than - combo timer ]
On your last combo (in this case the third one) add a property actuator connected with an “or” controller which sets the property “combo” back to 0, closing the loop and starting the combo chain from the start again nest time you press the attack key.
Connected to the same “or” controller, add another property sensor which detects if the property “combo timer” went over a certain value.
In all action games, if you wait too long with executing a combo, the combo will be reset to the start. The property sensor detecting the property “combo timer” will make sure this happens.
And that’s it!
If you’ve followed this tutorial you will have created a combo system for you character!
There’s just one more thing I’d like to add, which isn’t very important to the combo system itself, but might still be nice to know.
As it is currently, you’d still be able to move the character around like normal while executing the combo.
Most action games I know do not allow to move/run normally while executing a combo, but instead the character takes a step forward with each attack.
This is solved easily and is likely the only time you’ll need to use another logic state:
Make sure that you character physics box (the one thing responsible for all your character movement) can detect the combo messages. That, or make your attack key send a message specifically to the physics box.
[ Message - (your message) ]-------------[ and ]-----------------[ state - set state - (your state) ]
The next state is where the actual step movement will happen.
[ Always - tap ]-----------------------------[ or ]-------------------[ motion - character motion - (your speed/direction) ]
[ Message - (your message) ]
The “always” sensor has the “tap” toggle active. This makes sure the signal gets sent only once to the actuator.
The message sensor will detect the same message that changed the state of the physics cube to continue the steps when the attack key gets pressed multiple times.
Also make sure that your “combo timer” property sends a message to the physics box if the timer is above a certain value. This can be easily done by adding a message actuator to your final attack move’s “or” controller.
This will make sure that the logic state of the physics box will return to normal after a delay.
I hope this is helpful to someone.