script for a fighting system like Street Fighter

StrikerX

Member
Hi, I'm trying to create a script for a fighting system like Street Fighter, 1v1 but with Z-axis movement working. So, when holding "moveleft," the player move left and it doesn't turn around or turn player back to the enemy. The character always faces where the opponent is. This way, when holding back, the player uses the backwalk and stays facing the opponent. It worked, but the Z buttons don't function in this backwalk.

The moveup and movedown buttons are simply ignored in the backwalk animations.

I tried replacing the backwalk with a Follow22, but the result is the same. What is wrong with my script?

Code:
anim    idle
    loop    1
    delay    20
    bbox    86 17 68 541
    offset    106 545
    frame    data/chars/template/1_0-0.png
@script
    void self = getlocalvar("self");
    int plyr  = getentityproperty(self,"playerindex");
    void target = findtarget(self);

    if(!target) return;

    float x  = getentityproperty(self,"x");
    float Tx = getentityproperty(target,"x");
    int dir  = (Tx < x) ? 0 : 1;

    changeentityproperty(self,"direction",dir);

    // BACK
    if( (dir==1 && playerkeys(plyr,0,"moveleft")) ||
        (dir==0 && playerkeys(plyr,0,"moveright")) )
    {
        performattack(self, openborconstant("ANI_backwalk"));
    }

    // FORWARD
    else if( (dir==1 && playerkeys(plyr,0,"moveright")) ||
             (dir==0 && playerkeys(plyr,0,"moveleft")) )
    {
        performattack(self, openborconstant("ANI_WALK"));
    }
@end_script

    frame    data/chars/template/1_0-0a.png

anim    backwalk
    loop    1
    delay    8
    bbox    9 16 68 270
    offset    71 554
    frame    data/chars/template/1_0-11.png
@script
    void self = getlocalvar("self");
    int plyr  = getentityproperty(self,"playerindex");
    void target = findtarget(self);

    float speed = 2;

    if(!target) return;

    float x  = getentityproperty(self,"x");
    float Tx = getentityproperty(target,"x");
    int dir  = (Tx < x) ? 0 : 1;

    changeentityproperty(self,"direction",dir);

    if( (dir==1 && playerkeys(plyr,0,"moveleft")) ||
        (dir==0 && playerkeys(plyr,0,"moveright")) )
    {
        changeentityproperty(self,"velocity",
            dir==1 ? -speed : speed, 0, 0);
    }
    else
    {
        changeentityproperty(self,"velocity",0,0,0);
        setidle(self, openborconstant("ANI_IDLE"));
    }
@end_script
    offset    70 554
    frame    data/chars/template/1_0-12.png
 
Last edited:
Solved. AI showed me the correct code; now the player always faces the enemy, even if player moveleft, moveright, movedown or moveup. Reminded me now God of War.

Code:
anim    backwalk
    loop    1
    delay    8
    bbox    9 16 68 270
    offset    71 554
    frame    data/chars/template/1_0-11.png
@script
    void self = getlocalvar("self");
    int plyr  = getentityproperty(self,"playerindex");
    void target = findtarget(self);

    float xspeed = 3;
    float zspeed = 2;

    if(!target) return;

    float x  = getentityproperty(self,"x");
    float Tx = getentityproperty(target,"x");
    int dir  = (Tx < x) ? 0 : 1;

    float vx = 0;
    float vz = 0;

    changeentityproperty(self,"direction",dir);

    // BACK
    if( (dir==1 && playerkeys(plyr,0,"moveleft")) ||
        (dir==0 && playerkeys(plyr,0,"moveright")) )
    {
        vx = (dir==1 ? -xspeed : xspeed);

        if(playerkeys(plyr,0,"moveup"))   vz = -zspeed;
        if(playerkeys(plyr,0,"movedown")) vz =  zspeed;

        // ORDEM CORRETA: X , Z , Y
        changeentityproperty(self,"velocity", vx, vz, 0);
    }
    else
    {
        changeentityproperty(self,"velocity",0,0,0);
        setidle(self, openborconstant("ANI_IDLE"));
    }
@end_script

    offset    70 554
    frame    data/chars/template/1_0-12.png

[\CODE]
 
Solved. AI showed me the correct code; now the player always faces the enemy, even if player moveleft, moveright, movedown or moveup. Reminded me now God of War.

Code:
anim    backwalk
    loop    1
    delay    8
    bbox    9 16 68 270
    offset    71 554
    frame    data/chars/template/1_0-11.png
@script
    void self = getlocalvar("self");
    int plyr  = getentityproperty(self,"playerindex");
    void target = findtarget(self);

    float xspeed = 3;
    float zspeed = 2;

    if(!target) return;

    float x  = getentityproperty(self,"x");
    float Tx = getentityproperty(target,"x");
    int dir  = (Tx < x) ? 0 : 1;

    float vx = 0;
    float vz = 0;

    changeentityproperty(self,"direction",dir);

    // BACK
    if( (dir==1 && playerkeys(plyr,0,"moveleft")) ||
        (dir==0 && playerkeys(plyr,0,"moveright")) )
    {
        vx = (dir==1 ? -xspeed : xspeed);

        if(playerkeys(plyr,0,"moveup"))   vz = -zspeed;
        if(playerkeys(plyr,0,"movedown")) vz =  zspeed;

        // ORDEM CORRETA: X , Z , Y
        changeentityproperty(self,"velocity", vx, vz, 0);
    }
    else
    {
        changeentityproperty(self,"velocity",0,0,0);
        setidle(self, openborconstant("ANI_IDLE"));
    }
@end_script

    offset    70 554
    frame    data/chars/template/1_0-12.png

[\CODE]

That might work, but you're fighting the engine. You would be much better off using the native force direction in a think event script. Just calculate which side the nearest opponent is on, set forcedirection property accordingly, and let OpenBOR do the rest. It will be smoother, get all that ugly inline script out of your model sheet, and let you use the engine's native Backwalk animations without any fuss.

DC
 
Back
Top Bottom