• 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!

Character walking with other keys

D

DarlesLSF

Guest
Hello, I set the directional keys for moving my character (vk_down, vk_up, vk_left and vk_right), but when I press any other key, this happen:


Why this happen?

Step event:
Code:
var direita = keyboard_check(vk_right);
var esquerda = keyboard_check(vk_left);
var cima = keyboard_check(vk_up);
var baixo = keyboard_check(vk_down);

vel_h = (direita - esquerda) * vel;
vel_v = (baixo - cima) * vel;
 
T

Taddio

Guest
in the create event
Code:
velanim = .12;
vel = 2;
vel_h = 0;
vel_v = 0;
There is nothing that adds your variables to your player's X.
Like
x += hsp;
Or something like that (NOT in the create event, tho)
 

Rob

Member
in the create event
Code:
velanim = .12;
vel = 2;
vel_h = 0;
vel_v = 0;
Like Taddio says you need to add/decrease the instance's x/y values by the value that's stored inside vel_h and vel_v otherwise that character will never move =P
 
D

DarlesLSF

Guest
Like Taddio says you need to add/decrease the instance's x/y values by the value that's stored inside vel_h and vel_v otherwise that character will never move =P
But my character move normally, what Im saying its when I press any key of the keyboard, my character does the animation of walking, like the gif above. What I want its to know how to stop that.
In the gif, Im pressing the H in the keyboard and the character does the animation of walking. And that happens with any key, but only move with the directional keys.
 

Spam1985

Member
Well there's nothing in the code you've provided that would cause that to happen.

Either there is some other code somewhere that is causing it or your keyboard is possessed by Satan.
 
T

Taddio

Guest
How to stop the animation is easy, just throw in something like
if keyboard_check(vk_nokey) {image_speed = 0;}
But as @Spam1985 said, if this code makes your player move, I'd contact an exorcist priest, because NOTHING in there updates your player position! Do you have keyboard events that manages movements, or just the step event you showed us?
EDIT: when you say your "character moves", do you mean actually changing position on the screen, or only "moonwalking" on the same spot (animation without any shift in (x,y)?
 
D

DarlesLSF

Guest
here's the full code:
Code:
var direita = keyboard_check(vk_right);
var esquerda = keyboard_check(vk_left);
var cima = keyboard_check(vk_up);
var baixo = keyboard_check(vk_down);

vel_h = (direita - esquerda) * vel;
vel_v = (baixo - cima) * vel;

if (place_meeting(x + vel_h, y, obj_parede))
{
    while (!place_meeting(x + sign(vel_h), y, obj_parede))
        {
            x += sign(vel_h);
        }
    vel_h = 0;
}
x += vel_h;

if (place_meeting(x, y + vel_v, obj_parede))
{
   while (!place_meeting(x, y + sign(vel_v), obj_parede))
    {
        y += sign(vel_v);
    }
    vel_v = 0;
}
y += vel_v;
 
D

DarlesLSF

Guest
I solved that using the "nokey" and setting the image_speed to 0.
 

Spam1985

Member
That all looks totally fine if a little bit Portuguese.

There has to be some other code somewhere else that is doing it.
 
Top