M
Mike?
Guest
Hello! This is my first time posting here and I'm in the middle of building my movement in Game Maker studio 2. I have horizontal movement down, however I can't seem to get the dashing ability work properly.
In the create event, pretty straight forward stuff:
move_speed = 300;
key_left = ord("A");
key_right = ord("D");
key_dash = vk_space;
is_dashing = false;
dash_speed = move_speed * 2;
dash_duration = 20;
dash_execution = 0;
And in my step event:
var timepassed = delta_time / 1000000;
var pixelsthisframe = move_speed * timepassed
var xdir = keyboard_check(key_right) - keyboard_check(key_left);
if xdir != 0
//xdir is key_right - key_left
{
var h_dir = point_direction(0, 0, xdir, 0);
//point direction is a function that returns a direction
x += lengthdir_x(pixelsthisframe, h_dir);
}
Then the real problem. The dashing code. The sprite can dash and is_dashing resets, however what it doesn't do is keep the player's movement speed from increasing with each press of the space bar, nor does it reset to the base move speed.
if (keyboard_check_pressed(key_dash)) and not is_dashing
{
is_dashing = true;
var dash_dir = sign(move_speed);
move_speed += dash_speed * dash_dir;
}
if is_dashing == true
{
friction += 150;
is_dashing = false;
move_speed = move_speed;
}
Thank you in advance, I'm still really new to coding.
In the create event, pretty straight forward stuff:
move_speed = 300;
key_left = ord("A");
key_right = ord("D");
key_dash = vk_space;
is_dashing = false;
dash_speed = move_speed * 2;
dash_duration = 20;
dash_execution = 0;
And in my step event:
var timepassed = delta_time / 1000000;
var pixelsthisframe = move_speed * timepassed
var xdir = keyboard_check(key_right) - keyboard_check(key_left);
if xdir != 0
//xdir is key_right - key_left
{
var h_dir = point_direction(0, 0, xdir, 0);
//point direction is a function that returns a direction
x += lengthdir_x(pixelsthisframe, h_dir);
}
Then the real problem. The dashing code. The sprite can dash and is_dashing resets, however what it doesn't do is keep the player's movement speed from increasing with each press of the space bar, nor does it reset to the base move speed.
if (keyboard_check_pressed(key_dash)) and not is_dashing
{
is_dashing = true;
var dash_dir = sign(move_speed);
move_speed += dash_speed * dash_dir;
}
if is_dashing == true
{
friction += 150;
is_dashing = false;
move_speed = move_speed;
}
Thank you in advance, I'm still really new to coding.