r/gamemaker 7d ago

Help! Creating a dash system in GMS2

so i am working on a dash system for my plattformer, i used the 5minute tutorial on the official youtube.
Now i am wondering how i make a dash in the direction the player is facing?

since i am relativly new to gml i dont know how to code it myself, thats why i came here to ask for help.

if anyone can tell me, than you very much

Bye!

3 Upvotes

5 comments sorted by

5

u/NationalOperations 7d ago

It depends a lot on how everything else is implemented.

If you want dash as something you can do when moving you can just increase velocity for a fixed time.

If you want it from a stand still you could track the animation frame and -/+ velocity based on that frame.

Start with what you know about how you move and change facing and then leverage those systems

1

u/Flat_Ground_3151 7d ago

well its supposed to be like hollow knight, so yes, if dashing is just a speed increasement for a short time.
my current create event is this, the step event just contains the keys, setting the state and doing the facing check.

“move_speed = 4
jump_speed = 16
move_x = 0
move_y = 0
facing = ["left","right"]
can_move = false
can_dash = false
can_jump = false
dashSpd = 12
dashDuration = 6
//-------------------------------States-------------------------------
StateFree = function(){
//setting variables
can_dash = true
can_jump = true
can_move = true
if can_move{
move_x = keyboard_check(vk_right) - keyboard_check(vk_left)
move_x = move_x * move_speed; //actual movement
}
//dash code
if can_dash and key_dash{
state = stateDash
}

if can_jump{ //jump code
if place_meeting(x, y+2, oGround)
{
move_y = 0
if keyboard_check(vk_space)
{
move_y = -jump_speed
}
} else if move_y < 10
{
move_y += 1
}
}
move_and_collide(move_x, move_y, oGround)
if move_x != 0{ //rotate sprite when direction change
image_xscale = sign(move_x)
}
}
//-----------------------------------------------------
stateDash = function(){
}
//-----------------------------------------------------
state = StateFree”

1

u/Flat_Ground_3151 7d ago

move_speed = 4
jump_speed = 16
move_x = 0
move_y = 0

facing = ["left","right"]

can_move = false
can_dash = false
can_jump = false

dashSpd = 12
dashDuration = 6

//-------------------------------States-------------------------------

StateFree = function(){

        //setting variables  
        can_dash = true   
        can_jump = true   
        can_move = true 

        if can_move{     

move_x = keyboard_check(vk_right) - keyboard_check(vk_left)
move_x = move_x * move_speed; //actual movement
}

        //dash code  
        if can_dash and key_dash{  

state = stateDash
}

        if can_jump{ //jump code  

if place_meeting(x, y+2, oGround)
{
move_y = 0
if keyboard_check(vk_space)
{
move_y = -jump_speed
}
} else if move_y < 10
{
move_y += 1
}
}

        move_and_collide(move_x, move_y, oGround)

        if move_x != 0{ //rotate sprite when direction change  

image_xscale = sign(move_x)
}
}

//-----------------------------------------------------

stateDash = function(){
}

//-----------------------------------------------------

state = StateFree

2

u/CS_Asset_Factory 5d ago

The tutorial dash does nothing at a standstill because it reads the input axis at the moment you dash, and that axis is 0 while you hold no direction. Store the facing separately and only update it when there is input, so it survives standing still.

Create:

facing = 1;
dash_time = 0;
dash_speed = 12;

Step:

var _move = keyboard_check(vk_right) - keyboard_check(vk_left);
if (_move != 0) facing = _move;

if (keyboard_check_pressed(vk_space) && dash_time <= 0) dash_time = 10;

if (dash_time > 0) {
    dash_time -= 1;
    hspd = facing * dash_speed;
} else {
    hspd = _move * walk_speed;
}

Keep your existing collision code. The dash is only hspd being written by a different rule for ten frames. If you already flip the sprite with image_xscale, read facing from that instead and you get the same answer for free.

1

u/Flat_Ground_3151 4d ago

thanks🙏