Pressing 2 buttons at once
by PGames · in Torque 3D Professional · 09/20/2010 (9:55 am) · 6 replies
I'm trying to get my character to do a special attack when the player presses the keys "j" and "k" at the same time. The problem is, "j" is already assigned to a regular attack and so is "k," so when I press them at the same time, j's attack always plays:
moveMap.bindCmd(keyboard, "j", "fireNo1(0);","");
moveMap.bindCmd(keyboard, "k", "fireNo1(1);","");
moveMap.bindCmd(keyboard, "j k", "fireNo1(2);","");
I see that the "control" and "shift" keys could be assigned their own thing but still combine with another key to do something else. So, can I do that with regular keys, and if so, how?
moveMap.bindCmd(keyboard, "j", "fireNo1(0);","");
moveMap.bindCmd(keyboard, "k", "fireNo1(1);","");
moveMap.bindCmd(keyboard, "j k", "fireNo1(2);","");
I see that the "control" and "shift" keys could be assigned their own thing but still combine with another key to do something else. So, can I do that with regular keys, and if so, how?
#2
09/21/2010 (1:50 am)
Can you give an example of ActionMap::createEventDescriptor? I can't find much about it.
#3
I looked a littlebit deeper in the code, that´s complex to change... ;-)
Have you tried to script the double key action?
something like
Based on this you could also trigger with a time event, that you have a time window to execute some action moves, or even stop them if any key hasn't been pressed!
Is quite easier than hacking code in a very sensible area.
Ah and not to forget, supports your keyboard multiple input events? It should do so, so this approach is quite more flexible!
09/24/2010 (12:41 pm)
The function defines the possible actions taken from the bindCmd to the internal action layer.I looked a littlebit deeper in the code, that´s complex to change... ;-)
Have you tried to script the double key action?
something like
$doubleMove = 0;
// Stopmove not tested would say, this should also work with schedule(0,...)
function StopMove( %val )
{
$doubleMove &= ~%val;
}
function fireNo0( %val )
{
if( %val )
{
if( $doubleMove == 1 )
// MakeLeftAttackSpecialDuperAction
else
{
$doubleMove |= 2;
// To stop immediatly schedule( 32, NULL, StopMove, 2 );
// NormalNotHurtingJAction
}
}
else
$doubleMove &= ~2;
}
function fireNo1( %val )
{
if( %val )
{
if( $doubleMove == 2 )
// MakeRightAttackSpecialDuperAction
else
{
$doubleMove |= 1;
// To stop immediatly schedule( 32, NULL, StopMove, 1 );
// NormalNotHurtingKAction
}
}
else
$doubleMove &= ~1;
}
moveMap.bindCmd(keyboard, "j", fireNo0 );
moveMap.bindCmd(keyboard, "k", fireNo1 );Based on this you could also trigger with a time event, that you have a time window to execute some action moves, or even stop them if any key hasn't been pressed!
Is quite easier than hacking code in a very sensible area.
Ah and not to forget, supports your keyboard multiple input events? It should do so, so this approach is quite more flexible!
#4
If the other key is pressed you either set another flag (and let the timer fire when it does and based on both flags it knows what to do) or cancel the timer and act immediately.
This way if you hit a single key there's a small lag (say, 1/10th of a second) where you can hit the other key (3-6 frames, should be sufficient to catch both keys) and if not the action still fires off quickly enough that there isn't a perceivable delay to the player.
09/24/2010 (4:36 pm)
As Thomas mentioned, the best way to handle this is, on either key press set a short timer to actually take effect, and set a flag.If the other key is pressed you either set another flag (and let the timer fire when it does and based on both flags it knows what to do) or cancel the timer and act immediately.
This way if you hit a single key there's a small lag (say, 1/10th of a second) where you can hit the other key (3-6 frames, should be sufficient to catch both keys) and if not the action still fires off quickly enough that there isn't a perceivable delay to the player.
#5
You bind 'j' to a function.
When you press 'k' you activate a package that flips the previous function with a new one,but their names are the same.
When you release 'k' and deactivate the package,you call the previous function,that is not part of the package.
Now,when 'j' is active you have one code behaviour.
When both are active you have a different behaviour with the same binding.
Actually the double press action is doable in so many ways.I prefer to sum the boolean press results in moveManager,forming a new trigger set.When the trigger is active it means a double press is done.
09/24/2010 (5:18 pm)
Another one decision is to use activate / deactivate a package all the time.You bind 'j' to a function.
When you press 'k' you activate a package that flips the previous function with a new one,but their names are the same.
When you release 'k' and deactivate the package,you call the previous function,that is not part of the package.
Now,when 'j' is active you have one code behaviour.
When both are active you have a different behaviour with the same binding.
Actually the double press action is doable in so many ways.I prefer to sum the boolean press results in moveManager,forming a new trigger set.When the trigger is active it means a double press is done.
#6
09/25/2010 (2:33 pm)
Ivan, great idea with the package. You would need the timer to deactivate then, don't you? Use the package to implement a kind of runtime polymorphism is really interesting!
Torque 3D Owner Thomas
mercatronics
Hope that helps!