How do I set up a 3 hit combo
by Adam Schein · in Torque X 2D · 03/25/2009 (6:06 pm) · 2 replies
I'm trying to set up a 3 hit combo for the player object. I'm not sure how to go about this. Can someone list sample code or an algorithm or any other way of explaining how to do this in Torque 2D. Is there a way I can set up components to emulate a 3 hit combo or to provide custom code or any other method of achieving this?
About the author
Recent Threads
#2
In your ProcessTick method, you need to have a predicate that checks to see if your player has been hit and if so, reset all the combo variables, as in the if(nComboHits>3) block.
03/26/2009 (2:41 pm)
...forgot to add-In your ProcessTick method, you need to have a predicate that checks to see if your player has been hit and if so, reset all the combo variables, as in the if(nComboHits>3) block.
Torque Owner Talcott Langston
Off the top of my head, I'd try the following. This assumes only one opponent in the game but it would be easy to modify for multiple opponents:
Add the following variables to your player control component (or whatever component handles collisions with other objects):
const float maxComboTime = 2f;
bool bInCombo = false;
int nComboHits = 0;
float fComboTime = 0f;
In the ProcessTick method of the same class add:
// Keep track of how long it's taking to do the combo
if (bInCombo)
fComboTime += dt;
// Too long, reset variables
if (fComboTime > maxComboTime)
{
bInCombo = false;
nComboHits = 0;
fComboTime = 0;
}
Now, in your onCollision for the player object (or whatever function resolves successful hits) add:
if (successfulHit()) // Obviously you'll need your own predicate here.
{
bInCombo = true;
nComboHits++;
}
if (nComboHits > 3)
{
bInCombo = 0;
nComboHits = 0;
fComboTime = 0;
RegisterThreeHitCombo();
}
Once again, I came up with this literally as I was typing it, and it makes the assumption that 1) there's only one opponent in the game, otherwise you'd have to track who the last guy you hit was and 2) that any 3 hits make a 3 hit combo, otherwise you have to track whether the last hit "counts" toward a combo, but it should be easy to update for other scenarios and give you an idea of how to do it.