• All, Gmail is currently rejecting messages from my host. I have a ticket in process, but it may take some time to resolve. Until further notice, do NOT use Gmail for your accounts. You will be unable to receive confirmations and two factor messages to login.

Different anims for walking left/walking right

aL BeasTie

Well-known member
I've been wondering a while how difficult it would be to try make it so a character can have different animation for walking left and right.

so default anim WALK would be WALK RIGHT, I want a different one for WALK LEFT. (Ultimately I would want it for all directions, UP LEFT, UP RIGHT, DOWN LEFT, DOWN RIGHT)


My guess was trying with keyscript, but I thought I'd ask and see what others had to say first.
 
Last edited:
@Kratus Thanks again for the help

I just did a quick test without modifying your script at all just to see if it worked with WALK anim. It works perfectly!

I just need to update it now because my sprites have 8 frames for walking and they also have different facing directions for
DIAGONAL-UP-LEFT, DIAGONAL-UP-RIGHT, DIAGONAL-UP-LEFT and DIAGONAL-DOWN-RIGHT

walktest.png
 
@Kratus Thanks again for the help

I just did a quick test without modifying your script at all just to see if it worked with WALK anim. It works perfectly!

I just need to update it now because my sprites have 8 frames for walking and they also have different facing directions for
DIAGONAL-UP-LEFT, DIAGONAL-UP-RIGHT, DIAGONAL-UP-LEFT and DIAGONAL-DOWN-RIGHT

View attachment 7758
Great, glad the script works :)
 
@maxman - btw I added the Force Pain animations trick to the Scripts Index and directed it to your post.
Nice. I guess you find it helpful for changing frame within a pain animation without wasting more pain animations.

EDIT: Sorry. I forgot to show/should've shown you the source of entity which I got it from a couple of years ago after I posted. But I lost the actual source link that was in this forum made by Piccolo years ago. Here's painbox ent if you like to take a look at it.
 

Attachments

Last edited:
@Kratus - thanks again for the script. I'm just a little confused thou how to edit it properly.

I've added extra frames, each anim is 8 frames each
Code:
if(frame != 0 && frame != 1 && frame != 2 && frame != 3 && frame != 4 && frame != 5 && frame != 6 && frame != 7){updateframe(self, 2);}

- with the
Code:
{updateframe(self, 2);
- this number is setting the last frame or something else?

Code:
frame    data/chars/player/walk00.png #LEFT-RIGHT
frame    data/chars/player/walk01.png
frame    data/chars/player/walk02.png
frame    data/chars/player/walk03.png
frame    data/chars/player/walk04.png
frame    data/chars/player/walk05.png
frame    data/chars/player/walk06.png
frame    data/chars/player/walk07.png
@cmd    looper 2 9999
frame    data/chars/player/walkb00.png #RIGHT-LEFT

and the values for looper, I wasn't sure what should I be doing with these exactly.
 
The way looper works is to declare a certain frame number to start its loop, which is the first parameter. The second parameter is the value for how many times a given frame number begins to repeat.

- this number is setting the last frame or something else?
No. What I see from your code is that you're declaring it as third frame in an animation for it to start its loop. That loop begins with the third frame after it runs to the other frame where looper is. The simplest thing you can do is count the frames from the animation and double your walking frames as in two groups like this one.

Code:
frame    data/chars/player/walk00.png #LEFT-RIGHT 0
frame    data/chars/player/walk01.png #1
frame    data/chars/player/walk02.png #2
frame    data/chars/player/walk03.png #3
frame    data/chars/player/walk04.png #4
frame    data/chars/player/walk05.png #5
frame    data/chars/player/walk06.png #6
frame    data/chars/player/walk07.png #7
frame    data/chars/player/walk00.png #8 #Is this 9th frame
frame    data/chars/player/walk01.png #9
frame    data/chars/player/walk02.png #10
frame    data/chars/player/walk03.png #11
frame    data/chars/player/walk04.png #12
frame    data/chars/player/walk05.png #13
frame    data/chars/player/walk06.png #14
frame    data/chars/player/walk07.png #15
@cmd    looper 8 9999 #begin looping from the 9th frame?
frame    data/chars/player/walkb00.png #RIGHT-LEFT 16

Since I see too much frames in only one line from that script, you can separate this/these into a few lines if you like. It's just for your visual understanding which you don't have to put them all in one line.
C:
if(frame != 0 && frame != 1 && frame != 2 && frame != 3 &&
   frame != 4 && frame != 5 && frame != 6 && frame != 7 &&
   frame != 8 && frame != 9 && frame != 10 && frame != 11 &&
   frame != 12 && frame != 13 && frame != 14 && frame != 15){
    updateframe(self, 8);
    }

Kratus may answer this one better than me on this one since he was the one who made the rocket X missile loop.
 
@Kratus - thanks again for the script. I'm just a little confused thou how to edit it properly.
@aL BeasTie I reworked the code to make it simpler, this way you can edit by changing the values at the header related to the frame block interval and loop.

C:
void frameVel()
{//Update frame with velocity check
    void self = getlocalvar("self");
    void anim = getentityproperty(self, "animationID");

    if(anim == openborconstant("ANI_IDLE")){
        float max                = 0.6;
        float min                = 0.3;
        int dir                    = getentityproperty(self, "direction");
        int xVel                = getentityproperty(self, "xdir");
        int zVel                = getentityproperty(self, "zdir");
        int frame                = getentityproperty(self, "animpos");
        int frameBlock1            = (frame >= 0 && frame <= 3); //ENTIRE FRAME BLOCK INTERVAL
        int frameLoop1            = 2; //FRAME NUMBER USED BY THE LOOPER
        int frameBlock2            = (frame >= 4 && frame <= 7);
        int frameLoop2            = 6;
        int frameBlock3            = (frame >= 8 && frame <= 11);
        int frameLoop3            = 10;
        int frameBlock4            = (frame >= 12 && frame <= 15);
        int frameLoop4            = 14;
        int frameBlock5            = (frame >= 16 && frame <= 19);
        int frameLoop5            = 18;
        int rightDirection        = (xVel > max && dir == 1);
        int leftDirection        = (xVel < -max && dir == 0);
        int upDirection            = (xVel < min && xVel > -min) && (zVel < 0);
        int downDirection        = (xVel < min && xVel > -min) && (zVel > 0);
        int diagonalRightUp        = (xVel <= max && xVel >= min && dir == 1) && (zVel < 0);
        int diagonalRightDown    = (xVel <= max && xVel >= min && dir == 1) && (zVel > 0);
        int diagonalLeftUp        = (xVel >= -max && xVel <= -min && dir == 0) && (zVel < 0);
        int diagonalLeftDown    = (xVel >= -max && xVel <= -min && dir == 0) && (zVel > 0);

        //RIGHT DIRECTION
        if(rightDirection && !frameBlock1){
            updateframe(self, frameLoop1);
        }else

        //LEFT DIRECTION
        if(leftDirection && !frameBlock1){
            updateframe(self, frameLoop1);
        }else

        //DOWN DIRECTION
        if(downDirection && !frameBlock4){
            updateframe(self, frameLoop4);
        }else

        //UP DIRECTION
        if(upDirection && !frameBlock5){
            updateframe(self, frameLoop5);
        }else

        //DIAGONAL RIGHT DOWN DIRECTION
        if(diagonalRightDown && !frameBlock2){
            updateframe(self, frameLoop2);
        }else

        //DIAGONAL RIGHT UP DIRECTION
        if(diagonalRightUp && !frameBlock3){
            updateframe(self, frameLoop3);
        }else

        //DIAGONAL LEFT DOWN DIRECTION
        if(diagonalLeftDown && !frameBlock2){
            updateframe(self, frameLoop2);
        }else

        //DIAGONAL LEFT UP DIRECTION
        if(diagonalLeftUp && !frameBlock3){
            updateframe(self, frameLoop3);
        }
    }
}

The logic here is basically to skip the frame block where there's a looper, otherwise it will move the animation to a wrong frame. You don't need to repeat the same sequence twice, I put it just for safety and because each loop in my case has only two frames, but you can use just one for the looper.
So, I always change to the first frame in the second sequence.

1714505375252.png
 
@Kratus - thanks again for the help. I got it working properly this time.


Here's my code for reference
ondrawscript - walk.c
Code:
void main()
{//Update frame with velocity check
    void self = getlocalvar("self");
    void anim = getentityproperty(self, "animationID");


    if(anim == openborconstant("ANI_WALK")){
        float max                = 0.6;
        float min                = 0.3;
        int dir                  = getentityproperty(self, "direction");
        int xVel                 = getentityproperty(self, "xdir");
        int zVel                 = getentityproperty(self, "zdir");
        int frame                = getentityproperty(self, "animpos");
        int frameBlock1          = (frame >= 0 && frame <= 8); //ENTIRE FRAME BLOCK INTERVAL //WALK-RIGHT
        int frameLoop1           = 1; //FRAME NUMBER USED BY THE LOOPER
        int frameBlock2          = (frame >= 9 && frame <= 17); //WALK-LEFT
        int frameLoop2           = 10;
        int frameBlock3          = (frame >= 18 && frame <= 26); //DOWN-RIGHT
        int frameLoop3           = 19;
        int frameBlock4          = (frame >= 27 && frame <= 35); //UP-RIGHT
        int frameLoop4           = 28;
        int frameBlock5          = (frame >= 36 && frame <= 44); //DOWN-LEFT
        int frameLoop5           = 37;
        int frameBlock6          = (frame >= 45 && frame <= 53); //DOWN-RIGHT
        int frameLoop6           = 46;
        int rightDirection       = (xVel > max && dir == 1);
        int leftDirection        = (xVel < -max && dir == 0);
        int upDirection          = (xVel < min && xVel > -min) && (zVel < 0);
        int downDirection        = (xVel < min && xVel > -min) && (zVel > 0);
        int diagonalRightUp      = (xVel <= max && xVel >= min && dir == 1) && (zVel < 0);
        int diagonalRightDown    = (xVel <= max && xVel >= min && dir == 1) && (zVel > 0);
        int diagonalLeftUp       = (xVel >= -max && xVel <= -min && dir == 0) && (zVel < 0);
        int diagonalLeftDown    = (xVel >= -max && xVel <= -min && dir == 0) && (zVel > 0);


        //RIGHT DIRECTION
        if(rightDirection && !frameBlock1){
            updateframe(self, frameLoop1);
        }else


        //LEFT DIRECTION
        if(leftDirection && !frameBlock2){
            updateframe(self, frameLoop2);
        }else


        //DOWN DIRECTION
        if(downDirection && !frameBlock3){
            updateframe(self, frameLoop3);
        }else


        //UP DIRECTION
        if(upDirection && !frameBlock4){
            updateframe(self, frameLoop4);
        }else


        //DIAGONAL RIGHT DOWN DIRECTION
        if(diagonalRightDown && !frameBlock3){
            updateframe(self, frameLoop3);
        }else


        //DIAGONAL RIGHT UP DIRECTION
        if(diagonalRightUp && !frameBlock4){
            updateframe(self, frameLoop4);
        }else


        //DIAGONAL LEFT DOWN DIRECTION
        if(diagonalLeftDown && !frameBlock5){
            updateframe(self, frameLoop5);
        }else


        //DIAGONAL LEFT UP DIRECTION
        if(diagonalLeftUp && !frameBlock6){
            updateframe(self, frameLoop6);
        }
    }
}

Player's WALK ANIM
Code:
anim    walk
    bbox    57 34 16 62
    offset    64 96
    loop    0
    delay    1
    frame    data/chars/vguy/walk00.png
    delay    14
    frame    data/chars/vguy/walk00.png #LEFT-RIGHT
    frame    data/chars/vguy/walk01.png
    frame    data/chars/vguy/walk02.png
    frame    data/chars/vguy/walk03.png
    frame    data/chars/vguy/walk04.png
    frame    data/chars/vguy/walk05.png
    frame    data/chars/vguy/walk06.png
    frame    data/chars/vguy/walk07.png
    @cmd    looper 1 9999
    delay    1
    frame    data/chars/vguy/walkb00.png
    delay    14
    frame    data/chars/vguy/walkb00.png #RIGHT-LEFT
    frame    data/chars/vguy/walkb01.png
    frame    data/chars/vguy/walkb02.png
    frame    data/chars/vguy/walkb03.png
    frame    data/chars/vguy/walkb04.png
    frame    data/chars/vguy/walkb05.png
    frame    data/chars/vguy/walkb06.png
    frame    data/chars/vguy/walkb07.png
    @cmd    looper 10 9999
    delay    1
    frame    data/chars/vguy/down00.png
    delay    10
    frame    data/chars/vguy/down00.png #DIAGONAL-DOWN-RIGHT
    frame    data/chars/vguy/down01.png
    frame    data/chars/vguy/down02.png
    frame    data/chars/vguy/down03.png
    frame    data/chars/vguy/down04.png
    frame    data/chars/vguy/down05.png
    frame    data/chars/vguy/down06.png
    frame    data/chars/vguy/down07.png
    @cmd    looper 19 9999
    delay    1
    frame    data/chars/vguy/up00.png
    delay    10
    frame    data/chars/vguy/up00.png #DIAGONAL-UP-RIGHT
    frame    data/chars/vguy/up01.png
    frame    data/chars/vguy/up02.png
    frame    data/chars/vguy/up03.png
    frame    data/chars/vguy/up04.png
    frame    data/chars/vguy/up05.png
    frame    data/chars/vguy/up06.png
    frame    data/chars/vguy/up07.png
    @cmd    looper 28 9999
    delay    1
    frame    data/chars/vguy/downb00.png
    delay    10
    frame    data/chars/vguy/downb00.png #DIAGONAL-DOWN-LEFT
    frame    data/chars/vguy/downb01.png
    frame    data/chars/vguy/downb02.png
    frame    data/chars/vguy/downb03.png
    frame    data/chars/vguy/downb04.png
    frame    data/chars/vguy/downb05.png
    frame    data/chars/vguy/downb06.png
    frame    data/chars/vguy/downb07.png
    @cmd    looper 37 9999
    delay    1
    frame    data/chars/vguy/upb00.png
    delay    10
    frame    data/chars/vguy/upb00.png #DIAGONAL-UP-LEFT
    frame    data/chars/vguy/upb01.png
    frame    data/chars/vguy/upb02.png
    frame    data/chars/vguy/upb03.png
    frame    data/chars/vguy/upb04.png
    frame    data/chars/vguy/upb05.png
    frame    data/chars/vguy/upb06.png
    frame    data/chars/vguy/upb07.png
    @cmd    looper 46 9999
    frame    data/chars/misc/empty.png


Now I'm just trying to make the normal up and down change when facing LEFT. I'm missing something in my logic thou.

Code:
int    isFacing = getentityproperty(self, "facing"); //check what direction player is facing


//UP DIRECTION FACING LEFT
        if(isFacing == 0 && upDirection && !frameBlock5){
            updateframe(self, frameLoop5);
        }else
       
        //DOWN DIRECTION FACING LEFT
        if(isFacing == 0 && downDirection && !frameBlock6){
            updateframe(self, frameLoop6);
        }else
 
Now I'm just trying to make the normal up and down change when facing LEFT. I'm missing something in my logic thou.
Glad the new script works :)
I saw you are using the "facing" property, but honestly I don't know if it has the same effect as direction. I suggest trying to use direction instead and see if it solve the problem.
 
Back
Top Bottom