Solved Dodge Button Help

Question that is answered or resolved.

Aerisetta

Active member
I am trying to make a dodge button so if I press DODGE + DIRECTION it will dodge towards a direction.

Below I have code to dodge, the doge works BUT the dodge only works if I am not already walking.
If I am walking froward and press DODGE+DIRECTION, nothing happens.
If I press DODGE + DIRECTION from idle, the doge will happen.

I wish to be able to dodge forward even while walking froward.

DODGING BUTTONS
com U A2 freespecial41
com F A2 freespecial42
com D A2 freespecial43

anim walk
cancel 0 999 0 U A2 freespecial41
cancel 0 999 0 F A2 freespecial42
cancel 0 999 0 D A2 freespecial43
loop 1
delay 10
offset 130 250
bbox 77 10 97 265
frame data/chars/aerisetta/run01.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run02.png
frame data/chars/aerisetta/run03.png
@cmd setglobalvar "zoomentity" NULL()
sound data/sounds/Run.wav
frame data/chars/aerisetta/run04.png
frame data/chars/aerisetta/run05.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run06.png

anim freespecial41
jugglecost 1
delay 8
offset 130 275
@cmd spawner "trail" 0 0 0
sound data/sounds/magic.wav
@cmd dasher 0 0 -5 0
frame data/chars/aerisetta/attack301.png
@cmd randSound "A_Laugh1.wav" "A_Laugh2.wav" "A_Laugh2.wav"
frame data/chars/aerisetta/attack301.png
@cmd setglobalvar "zoomentity" NULL()

anim freespecial42
jugglecost 1
delay 8
offset 130 275
@cmd spawner "trail" 0 0 0
sound data/sounds/magic.wav
@cmd dasher 10 0 0 1
frame data/chars/aerisetta/attack301.png
@cmd randSound "A_Laugh1.wav" "A_Laugh2.wav" "A_Laugh2.wav"
frame data/chars/aerisetta/attack301.png
@cmd setglobalvar "zoomentity" NULL()

anim freespecial43
jugglecost 1
delay 8
offset 130 275
@cmd spawner "trail" 0 0 0
sound data/sounds/magic.wav
@cmd dasher 0 0 5 0
frame data/chars/aerisetta/attack301.png
@cmd randSound "A_Laugh1.wav" "A_Laugh2.wav" "A_Laugh2.wav"
frame data/chars/aerisetta/attack301.png
@cmd setglobalvar "zoomentity" NULL()
 
You can use anim up and anim down with the same numbers of frames as anim walk. That way, you can cancel it with a2 in anim walk to make it look like a hold-forward attack. Anim down to make it look like a hold-down attack and anim up, a hold-up attack. Without those 2, you can cancel it with a2 with holding up, forward, or down + attack.

Hold forward + attack:
Code:
anim walk
cancel 0 5 0 A2 freespecial42
loop 1
delay 10
offset 130 250
bbox 77 10 97 265
frame data/chars/aerisetta/run01.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run02.png
frame data/chars/aerisetta/run03.png
@cmd setglobalvar "zoomentity" NULL()
sound data/sounds/Run.wav
frame data/chars/aerisetta/run04.png
frame data/chars/aerisetta/run05.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run06.png

Hold up attack:
Code:
anim up
cancel 0 5 0 A2 freespecial41
loop 1
delay 10
offset 130 250
bbox 77 10 97 265
frame data/chars/aerisetta/run01.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run02.png
frame data/chars/aerisetta/run03.png
@cmd setglobalvar "zoomentity" NULL()
sound data/sounds/Run.wav
frame data/chars/aerisetta/run04.png
frame data/chars/aerisetta/run05.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run06.png

Hold down attack:
Code:
anim down
cancel 0 5 0 A2 freespecial43
loop 1
delay 10
offset 130 250
bbox 77 10 97 265
frame data/chars/aerisetta/run01.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run02.png
frame data/chars/aerisetta/run03.png
@cmd setglobalvar "zoomentity" NULL()
sound data/sounds/Run.wav
frame data/chars/aerisetta/run04.png
frame data/chars/aerisetta/run05.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run06.png

It works okay, but it's gonna be very stiff to command.

In case they don't work for you, but you want the command to be flexible in direction holds, you can use script like this. Look at keyint here for example. Also, you don't need anim up and anim down for it. Plus, you don't need cancel in anim walk if you are gonna use script. Pay attention to the command.

Code:
com a3 freespecial2 #heavy punch

Code:
anim    freespecial2 #High punch
    @cmd    makeOpponentBlock
    @cmd    keyint "ANI_ATTACK3" 0 "F" 0 # Hold forward with a certain attack button
    @cmd    attack1 0 66 0 "ANI_ATTACK6"
    bbox    7 0 58 102
    offset    26 99
    delay    8
    sound data/sounds/common/punch2.wav
    hitfx data/sounds/common/beat3.wav
    frame    data/chars/ryu/188.gif
    @cmd    makeOpponentBlock
    offset    22 98
    frame    data/chars/ryu/189.gif
    offset    22 93
    @cmd    makeOpponentBlock
    frame    data/chars/ryu/190.gif
    attack4 53 8 55 30 12 0 0 0 0 0
    offset    16 93
    @cmd    makeOpponentBlock
    frame    data/chars/ryu/191.gif
    attack4 0 0 0 0 0 0 0 0 0 0
    frame    data/chars/ryu/192.gif
    frame    data/chars/ryu/193.gif
    offset    19 96
    frame    data/chars/ryu/194.gif
    offset    21 99
    frame    data/chars/ryu/195.gif
    bbox    7 0 47 103
    offset    24 99
    @cmd    makeOpponentUnblock
    frame    data/chars/ryu/196.gif

Code:
anim    attack3 #Forward+HP
    delay    6
    offset    35 90
    @cmd    makeOpponentBlock
    frame    data/chars/ryu/269.gif
    offset    35 91
    frame    data/chars/ryu/270.gif
    offset    33 97
    frame    data/chars/ryu/271.gif
    offset    32 96
    frame    data/chars/ryu/272.gif
    offset    26 93
    frame    data/chars/ryu/273.gif
    offset    25 92
    frame    data/chars/ryu/274.gif
    offset    15 92
    frame    data/chars/ryu/275.gif
    offset    14 94
    frame    data/chars/ryu/276.gif
    offset    21 96
    frame    data/chars/ryu/277.gif
    @cmd    makeOpponentUnblock
    delay        1
    frame    data/chars/ryu/277.gif


Code:
void keyint(void Ani, int Frame, void Key, int Hflag)
{// Change current animation if proper key is pressed or released
// Animation is changed without attacking

    void self = getlocalvar("self");
    int Dir = getentityproperty(self, "direction");
    int iPIndex = getentityproperty(self,"playerindex"); //Get player index
    void iRKey;

      if (Key=="U"){ //Up Required?
        iRKey = playerkeys(iPIndex, 0, "moveup"); // "Up"
      } else if (Key=="D"){ //Down Required?
        iRKey = playerkeys(iPIndex, 0, "movedown"); // "Down"
      } else if (Key=="L"){ //Left Required?
        iRKey = playerkeys(iPIndex, 0, "moveleft"); // "Left"
      } else if (Key=="R"){ //Right Required?
        iRKey = playerkeys(iPIndex, 0, "moveright"); // "Right"
      } else if (Key=="F"){ //Forward Required?
        if (Dir == 0){ // Facing Left?
          iRKey = playerkeys(iPIndex, 0, "moveleft"); // "Left"
        } else { // Facing Right
          iRKey = playerkeys(iPIndex, 0, "moveright"); // "Right"
        }
      } else if (Key=="B"){ //Backward Required?
        if (Dir == 1){ // Facing Right?
          iRKey = playerkeys(iPIndex, 0, "moveleft"); // "Left"
        } else { // Facing Left
          iRKey = playerkeys(iPIndex, 0, "moveright"); // "Right"
        }
      } else if (Key=="A"){ //Attack Required?
        iRKey = playerkeys(iPIndex, 0, "attack"); // "Attack"
      }

      if (Hflag==1){ //Not holding the button case?
        iRKey = !iRKey; //Take the opposite condition
      }

      if (iRKey){
        if (Ani=="ANI_IDLE"){ // Going idle?
          setidle(self, openborconstant("ANI_IDLE")); //Be idle!
        } else {
          changeentityproperty(self, "animation", openborconstant(Ani),2);
        }
        changeentityproperty(self, "animpos", Frame); //Change frame
      }
}
 
or anyone know a game with a dodge button like the one im describing so I can go see
You can use anim up and anim down with the same numbers of frames as anim walk. That way, you can cancel it with a2 in anim walk to make it look like a hold-forward attack. Anim down to make it look like a hold-down attack and anim up, a hold-up attack. Without those 2, you can cancel it with a2 with holding up, forward, or down + attack.

Hold forward + attack:
Code:
anim walk
cancel 0 5 0 A2 freespecial42
loop 1
delay 10
offset 130 250
bbox 77 10 97 265
frame data/chars/aerisetta/run01.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run02.png
frame data/chars/aerisetta/run03.png
@cmd setglobalvar "zoomentity" NULL()
sound data/sounds/Run.wav
frame data/chars/aerisetta/run04.png
frame data/chars/aerisetta/run05.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run06.png

Hold up attack:
Code:
anim up
cancel 0 5 0 A2 freespecial41
loop 1
delay 10
offset 130 250
bbox 77 10 97 265
frame data/chars/aerisetta/run01.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run02.png
frame data/chars/aerisetta/run03.png
@cmd setglobalvar "zoomentity" NULL()
sound data/sounds/Run.wav
frame data/chars/aerisetta/run04.png
frame data/chars/aerisetta/run05.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run06.png

Hold down attack:
Code:
anim down
cancel 0 5 0 A2 freespecial43
loop 1
delay 10
offset 130 250
bbox 77 10 97 265
frame data/chars/aerisetta/run01.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run02.png
frame data/chars/aerisetta/run03.png
@cmd setglobalvar "zoomentity" NULL()
sound data/sounds/Run.wav
frame data/chars/aerisetta/run04.png
frame data/chars/aerisetta/run05.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run06.png

It works okay, but it's gonna be very stiff to command.

In case they don't work for you, but you want the command to be flexible in direction holds, you can use script like this. Look at keyint here for example. Also, you don't need anim up and anim down for it. Plus, you don't need cancel in anim walk if you are gonna use script. Pay attention to the command.

Code:
com a3 freespecial2 #heavy punch

Code:
anim    freespecial2 #High punch
    @cmd    makeOpponentBlock
    @cmd    keyint "ANI_ATTACK3" 0 "F" 0 # Hold forward with a certain attack button
    @cmd    attack1 0 66 0 "ANI_ATTACK6"
    bbox    7 0 58 102
    offset    26 99
    delay    8
    sound data/sounds/common/punch2.wav
    hitfx data/sounds/common/beat3.wav
    frame    data/chars/ryu/188.gif
    @cmd    makeOpponentBlock
    offset    22 98
    frame    data/chars/ryu/189.gif
    offset    22 93
    @cmd    makeOpponentBlock
    frame    data/chars/ryu/190.gif
    attack4 53 8 55 30 12 0 0 0 0 0
    offset    16 93
    @cmd    makeOpponentBlock
    frame    data/chars/ryu/191.gif
    attack4 0 0 0 0 0 0 0 0 0 0
    frame    data/chars/ryu/192.gif
    frame    data/chars/ryu/193.gif
    offset    19 96
    frame    data/chars/ryu/194.gif
    offset    21 99
    frame    data/chars/ryu/195.gif
    bbox    7 0 47 103
    offset    24 99
    @cmd    makeOpponentUnblock
    frame    data/chars/ryu/196.gif

Code:
anim    attack3 #Forward+HP
    delay    6
    offset    35 90
    @cmd    makeOpponentBlock
    frame    data/chars/ryu/269.gif
    offset    35 91
    frame    data/chars/ryu/270.gif
    offset    33 97
    frame    data/chars/ryu/271.gif
    offset    32 96
    frame    data/chars/ryu/272.gif
    offset    26 93
    frame    data/chars/ryu/273.gif
    offset    25 92
    frame    data/chars/ryu/274.gif
    offset    15 92
    frame    data/chars/ryu/275.gif
    offset    14 94
    frame    data/chars/ryu/276.gif
    offset    21 96
    frame    data/chars/ryu/277.gif
    @cmd    makeOpponentUnblock
    delay        1
    frame    data/chars/ryu/277.gif


Code:
void keyint(void Ani, int Frame, void Key, int Hflag)
{// Change current animation if proper key is pressed or released
// Animation is changed without attacking

    void self = getlocalvar("self");
    int Dir = getentityproperty(self, "direction");
    int iPIndex = getentityproperty(self,"playerindex"); //Get player index
    void iRKey;

      if (Key=="U"){ //Up Required?
        iRKey = playerkeys(iPIndex, 0, "moveup"); // "Up"
      } else if (Key=="D"){ //Down Required?
        iRKey = playerkeys(iPIndex, 0, "movedown"); // "Down"
      } else if (Key=="L"){ //Left Required?
        iRKey = playerkeys(iPIndex, 0, "moveleft"); // "Left"
      } else if (Key=="R"){ //Right Required?
        iRKey = playerkeys(iPIndex, 0, "moveright"); // "Right"
      } else if (Key=="F"){ //Forward Required?
        if (Dir == 0){ // Facing Left?
          iRKey = playerkeys(iPIndex, 0, "moveleft"); // "Left"
        } else { // Facing Right
          iRKey = playerkeys(iPIndex, 0, "moveright"); // "Right"
        }
      } else if (Key=="B"){ //Backward Required?
        if (Dir == 1){ // Facing Right?
          iRKey = playerkeys(iPIndex, 0, "moveleft"); // "Left"
        } else { // Facing Left
          iRKey = playerkeys(iPIndex, 0, "moveright"); // "Right"
        }
      } else if (Key=="A"){ //Attack Required?
        iRKey = playerkeys(iPIndex, 0, "attack"); // "Attack"
      }

      if (Hflag==1){ //Not holding the button case?
        iRKey = !iRKey; //Take the opposite condition
      }

      if (iRKey){
        if (Ani=="ANI_IDLE"){ // Going idle?
          setidle(self, openborconstant("ANI_IDLE")); //Be idle!
        } else {
          changeentityproperty(self, "animation", openborconstant(Ani),2);
        }
        changeentityproperty(self, "animpos", Frame); //Change frame
      }
}

Thank you, i used the first option, im dont 100% understand it yet but it works as i want :)
 
If you cancel in anim walk without having anims up and down, you're just gonna walk around holding the walk button and attack, so it'll perform the same cancel attack. anim up is used for walking facing upward, while anim down is used for walking facing downward, like facing the camera or the audience (or a viewer watching).
 
If you cancel in anim walk without having anims up and down, you're just gonna walk around holding the walk button and attack, so it'll perform the same cancel attack. anim up is used for walking facing upward, while anim down is used for walking facing downward, like facing the camera or the audience (or a viewer watching).

is it possible to do diagonal UP+FORWARD, DOWN+FORWARD dodge with this method?
 
I use single button inputs in my new double dragon game and this is how I would tackle your issue. first you need this animation script

C-like:
void key2ani(char ani, int mp, char key1, char key2)
{//msmalik681 change animation based on key press or combination
 //key inputs: "moveup" "movedown" "moveforward" "moveback"
 //press: 3=holding 1=press 2=release default holding.

void self = getentityproperty("self");
    int current_mp = getentityproperty(self,"mp");
    int dir = getentityproperty(self, "direction");  //Get current facing direction
    if(key1=="moveforward"){key1 = dir==0?"moveleft":"moveright";}
    if(key1=="moveback"){key1 = dir==0?"moveright":"moveleft";}
    if(key2=="moveforward"){key2 = dir==0?"moveleft":"moveright";}
    if(key2=="moveback"){key2 = dir==0?"moveright":"moveleft";}

        if ( ( playerkeys( getentityproperty(self,"playerindex"), 3, key1) || !key1 ) && ( playerkeys(getentityproperty(self,"playerindex"), 3, key2) || !key2 ) ) {
            if( current_mp >= mp ){
            changeentityproperty(self,"mp",current_mp-mp);
            } else if ( current_mp < mp ){ return 0; }
            changeentityproperty(self, "velocity", 0, 0, 0); //Stop moving!
            performattack (self, openborconstant("ani_" + ani)); //Change the animation.
        }
}

now setup everything like this :

DODGING BUTTONS
com A2 freespecial40 # this will cancel both walking and idle

anim walk
loop 1
delay 10
offset 130 250
bbox 77 10 97 265
frame data/chars/aerisetta/run01.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run02.png
frame data/chars/aerisetta/run03.png
@cmd setglobalvar "zoomentity" NULL()
sound data/sounds/Run.wav
frame data/chars/aerisetta/run04.png
frame data/chars/aerisetta/run05.png
sound data/sounds/Run.wav
frame data/chars/aerisetta/run06.png

anim freespecial40
loop 0
delay 1
offset 130 250
#dodge forward
@cmd key2ani "freespecial42" 0 "moveforward"
#dodge down
@cmd key2ani "freespecial43" 0 "movedown"
#dodge up
@cmd key2ani "freespecial41" 0 "moveup"
frame data/chars/aerisetta/run01.png #this should be the first frame of idle
 
Last edited:
@msmalik681, @maxman, @Aerisetta,

Hey guys, I mean no offense at all, but these solutions are way more complex and CPU intensive than they need to be. I just ran a live stream of adding single key dodge commands. The stream is long because I was explaining and experimenting, but the principal is very simple.

 
or anyone know a game with a dodge button like the one im describing so I can go see
@Aerisetta

SOR2X uses a very simple keyscript event for the dodge move since the first versions, maybe it can be useful for your game. Basically the script gets the current character velocity and applies it to the dodge move, no need to use animation scripts (used once only to stop the character at the end of the animation).

C:
void dodge()
{//Dodge with dash
    void self    = getlocalvar("self");
    void vAniID    = getentityproperty(self,"animationID");
    int iPIndex    = getlocalvar("player");
    float xdir    = getentityproperty(self,"xdir");
    float zdir    = getentityproperty(self,"zdir");
   
    //DEFAULT DODGE COMMAND
    if(vAniID == openborconstant("ANI_WALK") || vAniID == openborconstant("ANI_RUN")){
        if(playerkeys(iPIndex, 1, "attack3")){
            executeanimation(self, openborconstant("ANI_FOLLOW10"), 0);
            changeentityproperty(self, "velocity", xdir, zdir);
        }
    }
}

Code:
anim follow10 #DODGE
    loop    0
    delay    2
    offset    62 126
    frame    data/chars/heroes/axel/dodge00.png
        delay    8
    frame    data/chars/heroes/axel/dodge01.png
    frame    data/chars/heroes/axel/dodge02.png
    frame    data/chars/heroes/axel/dodge03.png
    frame    data/chars/heroes/axel/dodge04.png
        delay    20
    @cmd dasher 0 0 0
    bbox    48 76 28 52
    frame    data/chars/heroes/axel/dodge05.png

 
Back
Top Bottom