• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker problem with walk system

L

Lemon85

Guest
I'm trying to make a walking system where right, up, and down show the character facing right and left shows him facing left. When you move diagonally up or down to the right it works, but when you move either diagonally left/up or left/down, when you let go of the buttons, it automatically goes back to the right facing sprite.

This is what I have in the STEP for the player object:

Code:
if(keyboard_check(vk_left)&&keyboard_check(vk_down))
    {
     sprite_index = walkleft
    }
if(keyboard_check(vk_left)&&keyboard_check(vk_up))
    {
        sprite_index = walkleft
    }
and this is what I have in the Key-Down for the directions (but the sprite is different for the left):

Code:
sprite_index = walkright
x += -5;
then in the Key-Up I have (except the sprite is different again for the left):
Code:
sprite_index= rightdonothing;
 

Fleoh

Member
I didn't understang everything u_u
But there's a lot of way for doing this but you could use the direction for your sprite index if you use speed.

In your step event :

Code:
// Define your vars
var left = keyboard_check(vk_left);
var right = keyboard_check(vk_left);


if (left)
{
    sprite_index = spr_walkleft;
}

if (right)
{
    sprite_index = spr_walkright;
}

if (left) && (right) or !(left) && !(right) // If Left and right are pressed simultaneously or not pressed
{
    sprite_index = spr_walkright;
}
Or if you use the instance speed

Code:
if direction > 90 && direction < 270
{
    sprite_index = spr_walkright;
}
else // If your character is facing left
{
    sprite_index = spr_walkleft;
}
Watch this picture for understand how angles works in GM.
 

Attachments

Last edited:
L

Lemon85

Guest
I didn't understang everything u_u
But there's a lot of way for doing this but you could use the direction for your sprite index if you use speed.

In your step event :

Code:
// Define your vars
var left = keyboard_check(vk_left);
var right = keyboard_check(vk_left);


if (left)
{
    sprite_index = spr_walkleft;
}

if (right)
{
    sprite_index = spr_walkright;
}

if (left) && (right) or !(left) && !(right) // If Left and right are pressed simultaneously or not pressed
{
    sprite_index = spr_walkright;
}
Or if you use the instance speed

Code:
if direction > 90 && direction < 270
{
    sprite_index = spr_walkright;
}
else // If your character is facing left
{
    sprite_index = spr_walkleft;
}
Watch this picture for understand how angles works in GM.
You're right, I defined some variables and then played around with that for a little while and I got it to work. Thank you!
 
Top