• 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 Platformer dash ability

C

CookiePig

Guest
Hi! I just started out with GMS and tried to create my own code for a dash ability in a platformer. It works as intended EXCEPT when i try to use it while simultaniously pressing the up and left arrow key at the same time. If i try to use the dash then nothing happens. Any ide why this is the case? This is my code for the player object:


key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_up);
key_dash = keyboard_check_pressed(vk_space);

dash_cooldown -= 1;
dash_timeleft -= 1;

if (dash_timeleft > 0)
{
vsp = 0;
hsp = player_direction*dash_speed;
}
else
{
hsp = walksp*(key_right - key_left);
vsp += grv;
}


if (dash_cooldown < 0) and (key_dash == true)
{
dash_timeleft = dash_duration;
dash_cooldown = dash_cooldown_max;
}

#region vertical collision
if place_meeting(x,y+vsp,oWall)
{
while (!place_meeting(x,y+sign(vsp),oWall))
{
y += sign(vsp);
}
vsp = 0
jumps_left = jumps_max;
}
#endregion
#region horizontal collision
if place_meeting(x+(hsp),y,oWall)
{
while (!place_meeting(x+sign(hsp),y,oWall))
{
x+= sign(hsp);
}
hsp=0;
}
#endregion
#region jumping
if (key_jump) and (!jumps_left == 0) and (dash_timeleft < 1)
{
jumps_left -= 1;
vsp = -jump_height;
}
#endregion

if (hsp > 0) player_direction = right;
else if (hsp < 0) player_direction = left;

x += hsp;
y += vsp;
 

Simon Gust

Member
Guessing that the code order is wrong.
right now, player_direction is calculated after checking it for the dashing.
put
Code:
if (hsp > 0) player_direction = right;
else
if (hsp < 0) player_direction = left;
above
Code:
if (dash_timeleft > 0)
{
vsp = 0;
hsp = player_direction * dash_speed;
}
else
{
hsp = walksp * (key_right - key_left);
vsp += grv;
}
and try again. Maybe shuffle even more.
There is a basic rule to code ordering:
1 define input
2 calculate motion
3 execute collision (including x+= hsp, y += vsp)
4 animation
 
C

CookiePig

Guest
Guessing that the code order is wrong.
right now, player_direction is calculated after checking it for the dashing.
put
Code:
if (hsp > 0) player_direction = right;
else
if (hsp < 0) player_direction = left;
above
Code:
if (dash_timeleft > 0)
{
vsp = 0;
hsp = player_direction * dash_speed;
}
else
{
hsp = walksp * (key_right - key_left);
vsp += grv;
}
and try again. Maybe shuffle even more.
There is a basic rule to code ordering:
1 define input
2 calculate motion
3 execute collision (including x+= hsp, y += vsp)
4 animation
Thanks for the tip, very helpful for a beginner. Didnt solve this particular problem though.
 
C

CookiePig

Guest
You should also be aware of keyboard ghosting. Some key combinations simply won't register.
This seems to be the case. The keyboard doesnt seem to register more inputs if up and left arrow key is held down at the same time. Thanks a bunch!
 
N

Nyarlathotep

Guest
I'm trying to use this to help me make a working dash but it doesn't seem to be working for me:
if (dash_timeleft > 0) and (Dash) and (hasdashed = false)
{

vsp = 0;
hsp = image_xscale * dash_speed;
dash_timeleft -= 1;
}
if (dash_timeleft <= 0)
{
hasdashed = true;
hsp = move * walkspd;
vsp = vsp + grv;
}
Any help?
 
Top