Page 1 of 1

Simple ANTI-MOONWALK script

PostPosted: Thu May 17, 2012 4:56 am
by Hblade
Ever have that moonwalk bug? Now you can fix it easily with 1 line of code
(NOTE: THIS IS FOR VERY BASIC MOVEMENT STYLE, SIMPLE LEFT AND RIGHT ONLY.. Does not include jumping animations, crouching etc)
Code: Select all
void doPlayer(int speed, char*walkLeft, char*walkRight, char*standLeft, char*standRight)
{
    char*key=GetKeyState();
    int dir=key[KEY_RIGHT]-key[KEY_LEFT];
    switch(dir)
    {
        case 0: break;
        case 1: ChangeAnimation("Event Actor", walkRight, NO_CHANGE); break;
        case -1: ChangeAnimation("Event Actor", walkLeft, NO_CHANGE); break;
    }
 
    x+=(dir*speed);
 
    if(dir==0)
    {
        if(animindex==getAnimIndex(walkRight))
        {
            ChangeAnimation("Event Actor", standRight, NO_CHANGE);
        }
        else if(animindex==getAnimIndex(walkLeft))
        {
            ChangeAnimation("Event Actor", standLeft, NO_CHANGE);
        }
    }
}



To use:
in Draw Actor of the player, write something similar to this
Code: Select all
doPlayer(5, "walkLeft", "walkRight", "standLeft", "standRight");


Whereas walkLeft is the name of the animation for walkLeft, etc.



Let me know if this works :)

Also:
use arrow keys to move

Re: Simple ANTI-MOONWALK script

PostPosted: Sun May 20, 2012 5:18 pm
by Bee-Ant
My method

Player -> Draw Actor:
Code: Select all
char Direct[4][16]={"Left","none","Right"};
char State[3][16]={"Stand", "Walk"};
char *key=GetKeyState();
int dir, state=(key[KEY_RIGHT]||key[KEY_LEFT]), speed=5;
char str[64];
x+=dir*speed;
sprintf(str,"%s%s",State[state],Direct[dir+1]);
ChangeAnimation("Event Actor", str, NO_CHANGE);
dir=key[KEY_RIGHT]-key[KEY_LEFT];


That's all :)

Requirement:
- Player with "StandLeft", "StandRight", "WalkLeft", and "WalkRight" animations
- Move it with Arrow Left and Right keys

Re: Simple ANTI-MOONWALK script

PostPosted: Mon May 21, 2012 1:08 am
by Hblade
Very excellent bee! I'd expect amazing code from you :)