Perfect Anti-Moonwalk
![Post Post](styles/prosilver/imageset/icon_post_target.gif)
![Very Happy :D](http://game-editor.com/forum/images/smilies/icon_biggrin.gif)
first: make a var called Left and Make a Var called Right and also a Var called AnimFinish. when the left key is pressed LEft = 1; and Same with the right(only use the Right Var) and o nthe animation finish event have this: AnimFinish = 1; also have that for when the left or right keys are released.
![Very Happy :D](http://game-editor.com/forum/images/smilies/icon_biggrin.gif)
- Code: Select all
Left = 1;
if (Left == 1 && Right == 0)
{
ChangeAnimationDirection("Event Actor", FORWARD);
xvelocity = - 3;
}
if (Left == 1 && Right == 1)
{
xvelocity = 0;
}
if(AinimFinish == 1 && Left == 1 && Right == 0)
{
ChangeAnimation("Event Actor", "KnightLeft1", FORWARD);
AinimFinish = 0;
}
and for the right key pressed:
- Code: Select all
Right = 1;
if (Left == 0 && Right == 1)
{
ChangeAnimationDirection("Event Actor", FORWARD);
xvelocity = - 3;
}
if (Left == 1 && Right == 1)
{
xvelocity = 0;
}
if(AinimFinish == 1 && Left == 0 && Right == 1)
{
ChangeAnimation("Event Actor", "KnightRight1", FORWARD);
AinimFinish = 0;
}
remember to have Left and Right at 0 when both keys are up
![Very Happy :D](http://game-editor.com/forum/images/smilies/icon_biggrin.gif)
also for the repeated key down events, without any extra vars exept AnimFinish you could do For the key Right Event:
- Code: Select all
char *key=GetKeyState();
if (key[KEY_RIGHT] == 1 && key[KEY_LEFT] == 0)
{
x += 5;
if(AnimFinish == 1)
{
ChangeAnimation("Event Actor", "KnightRight1", FORWARD);
AnimFinish = 0;
}
}
if (key[KEY_RIGHT] == 1 && key[KEY_LEFT] == 1)
{
ChangeAnimationDirection("Event Actor", FORWARD);
}
and for the repeated left use:
- Code: Select all
char *key=GetKeyState();
if (key[KEY_RIGHT] == 0 && key[KEY_LEFT] == 1)
{
x -= 5;
if(AnimFinish == 1)
{
ChangeAnimation("Event Actor", "KnightLeft1", FORWARD);
AnimFinish = 0;
}
}
if (key[KEY_RIGHT] == 1 && key[KEY_LEFT] == 1)
{
ChangeAnimationDirection("Event Actor", FORWARD);
}
you could also use xvelocity += or -= or = instead of x += or x -=
or x *= or x /= ect.