Animated can't walk

I

inashilmiana

Guest
anyone, i need help. i'm newbie using gms 2. i make a palyer run with animated but can't walk if i press the W button before. can anyone explain that ?
Code:
key_left = keyboard_check(vk_left) || keyboard_check(ord("A"));
key_right = keyboard_check(vk_right) || keyboard_check(ord("D"));
key_up = keyboard_check_pressed(vk_up)|| keyboard_check(ord("W"));

var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp + grv;

if (place_meeting(x,y+1,oWall)) && (key_up)
{
    vsp = -7;
}
 

if (place_meeting(x+hsp,y, oWall))
{
    while (!place_meeting(x+sign(hsp),y,oWall))
    {
        x = x + sign(hsp)
    }
    hsp = 0;
}
x = x + hsp;
    
if (place_meeting(x,y+vsp, oWall))
{
    while (!place_meeting(x, y+sign(hsp),oWall))
    {
        y = y + sign(vsp)
    }
    vsp = 0;
}
y = y + vsp ;
    

if (!place_meeting(x,y+1,oWall))
{
    sprite_index = rPlayerA;
    image_speed = 0;
    if (sign(vsp) >0) image_index = 1; else image_index = 0;
}
else
{
    image_speed = 1;
    if (hsp == 0)
    {
        sprite_index = rPlayer;
    }
    else
    {
        sprite_index = rPlayerR;
    }
}

if (hsp !=0) image_xscale =sign(hsp);
 

obscene

Member
if (place_meeting(x,y+1,oWall)) && (key_up)
{
vsp = -7;
}

Why check for a collision below the player before moving up?
 
S

seanm

Guest
if (place_meeting(x,y+1,oWall)) && (key_up)
{
vsp = -7;
}

Why check for a collision below the player before moving up?
Because he wants to make sure he's on the ground before he jumps


------------


If I had to guess what your problem is OP I would guess this
Code:
if (place_meeting(x,y+vsp, oWall))
{
   while (!place_meeting(x, y+sign(hsp),oWall)) <----You've written hsp instead of vsp here
   {
       y = y + sign(vsp)
   }
   vsp = 0;
}
y = y + vsp ;
 
I

inashilmiana

Guest
Because he wants to make sure he's on the ground before he jumps


------------


If I had to guess what your problem is OP I would guess this
Code:
if (place_meeting(x,y+vsp, oWall))
{
   while (!place_meeting(x, y+sign(hsp),oWall)) <----You've written hsp instead of vsp here
   {
       y = y + sign(vsp)
   }
   vsp = 0;
}
y = y + vsp ;
Sir maybe can you help me, i'm making an enemy but cant walk just stuck in the same place
this my code

create

vsp = 0;
grv = 0.3;
walksp = 3;
hsp = walksp;

hp = 30;
flash = 0;
hitfrom = 0;

step

vsp = vsp + grv;


if (place_meeting(x+hsp,y,oWall))
{
while (!place_meeting(x+sign(hsp),y,oWall))
{
x = x + sign(hsp);
}
hsp = -hsp;
}
x = x + hsp;

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


if (!place_meeting(x,y+1,oWall))
{

sprite_index = rEnemyA;
image_speed = 0;
if (sign(vsp) >0) image_index = 1; else image_index = 0;
}
else
{

image_speed = 1;
if (hsp == 0)
{
sprite_index = rEnemy;
}
else
{
sprite_index = rEnemyR;
}
}

if (hsp !=0) image_xscale =sign(hsp);

begin step

if (hp <= 0)
{
with(instance_create_layer(x,y, layer, oDead))
{
direction = other.hitfrom;
hsp = lengthdir_x(3,direction);
vsp = lengthdir_y(3,direction)-2;
if (sign(hsp) !=0) image_xscale = sign(hsp);
}
instance_destroy();


}

draw

draw_self();

if (flash > 0 )
{
flash--;
shader_set(shWhite);
draw_self();
shader_reset();
}
 
S

seanm

Guest
If I had to guess I would say your collisions are setting hsp = 0, and nothing else in your step even resets the enemies move speed.

if you put hsp = 3 at the start of your enemies step event, does it move horizontally?
 
Top