Here is a simple method: create an actor integer called 'moving'. the reason it's an actor variable is so other actors can use it too. On your player actor, it should be in one of three values: -1 (moving left), 0 (stopped) or 1 (moving right). Other metheds migh make use of more variables, such as moving, turning direction, it depends on what you want to do with it. For this case we'll just use moving. On your players draw actor event, put this script:
- Code: Select all
x += moving * 5;//adjust the five to suit your need
An alternative is to use velocity variables so you start increasing velocity when you start moving, rather than be either moving or not. (you could use another variable with this, too, to make situations like on ice, for example, you don't want to speed up as quickly). For the purpose of this example, we'll just stick with the simple method.
Now, this will move you according to the moving variable, but we still need to set it and change animations.
On keydown->right(no repeat), put this script:
- Code: Select all
if (moving != 1)
{
ChangeAnimation("Event Actor", "WalkRight", FORWARD);//substitute the name of your animation
moving = 1;
}
On keydown->left(no repeat), put a similar script:
- Code: Select all
if (moving != -1)
{
ChangeAnimation("Event Actor", "WalkLeft", FORWARD);//substitute the name of your animation
moving = -1;
}
Now, add two keyup events:
left:
- Code: Select all
if (moving == -1)
{
moving = 0;
ChangeAnimation("Event Actor", "StopLeft", FORWARD););//substitute the name of your animation
}
right:
- Code: Select all
if (moving == 1)
{
moving = 0;
ChangeAnimation("Event Actor", "StopRight", FORWARD););//substitute the name of your animation
}
I think this should do what you want. If you have problems, or any other questions, just ask.