[SOLVED]not sure how to fix my dash

X

xCrazyxSinner13x

Guest
my dash button works but i wont dash while the character is moving left or right but it does dash while in the air or standing still. Here is the code for my dash
//code
if((key_dash) and sprite_index = spr_player_left)
{
hspd=spd*-4;
}
 

The-any-Key

Member
What code make key_dash=true?

You need to post more code. The code you posted just say:
if key_dash is true and the sprite index is spr_player_left set hspd to spd*-4

The problem must be somewhere else in the code.
 
X

xCrazyxSinner13x

Guest
What code make key_dash=true?

You need to post more code. The code you posted just say:
if key_dash is true and the sprite index is spr_player_left set hspd to spd*-4

The problem must be somewhere else in the code.

this the creat event code for my player
///Initialize Variable
// The Game main gravity
grav = 1;
// Player main speed
spd = 4;
// Player how high can jump
jspd = 12;
// IF player not moving speed zero
hspd = 0;
// IF player not moving speed zero
vspd = 0;
// Player friction speed
fric = 1;
//variable to double jump the higher the number the more jumps player can do
doublejump = 1;


this the code for my step event for my player
/// Platfrom physics
var key_left = keyboard_check(ord("A"));
var key_right = keyboard_check(ord("D"));
var key_jump = keyboard_check_pressed(vk_space);
var key_dash = keyboard_check_pressed(vk_shift);

//camera movement
camera_movement();

// Check for ground
if (place_meeting(x,y+1,obj_solid))
{
doublejump = 1;
vspd=0;

// Jumping
if (key_jump)
{
vspd = -jspd
}
}

// This is a else statment if the statement above is false then this statement will be true
else
{
//Gravity
if (vspd < 10)
{
vspd += grav;
}
if (keyboard_check_released(vk_space) && vspd <-4)
{
vspd = -4;
}
//checking for doublejump
if (doublejump > 0)
{
if (key_jump)
{
vspd = -jspd;
doublejump -= 1;
}
}
}

// dash speed left
if(key_dash) and sprite_index = spr_player_left
{
hspd=spd*-4;
}

// dash speed left
if(key_dash) and sprite_index = spr_player_right
{
hspd=spd*+4;
}

//moving right
if(key_right)
{
//sprite moving right the sprite changes to player right sprite
sprite_index = spr_player_right;
if(hspd < spd)
{
hspd += fric;
}
else
{
hspd = spd;
}

// Left Wall jump !key_left

if (place_meeting(x-1,y,obj_solid) && !place_meeting(x,y+1,obj_solid) && !key_left)
{
vspd = -jspd;

}
}

//moving left
if(key_left)
{
sprite_index = spr_player_left;
if(hspd > -spd)
{
hspd -= fric;
}
else
{
hspd = -spd;
}


// right Wall jump !key_right
if (place_meeting(x+1,y,obj_solid) && !place_meeting(x,y+1,obj_solid) && !key_right)
{
vspd = -jspd;

}
}

//Check for not moving
if((!key_right && !key_left) || (key_right && key_left))
{
if (hspd != 0)
{
if (hspd < 0)
{
hspd +=fric;
}
else
{
hspd -=fric;
}
}
}

//horizontal collision
if (place_meeting(x+hspd,y,obj_solid))
{
while (!place_meeting(x+sign(hspd),y,obj_solid))
{
x+= sign(hspd);
}
hspd = 0;
}

//move horizontally
x += hspd;

// Vertical collisions
if (place_meeting(x,y+vspd,obj_solid))
{
while (!place_meeting(x,y+sign(vspd),obj_solid))
{
y+= sign(vspd);
}
vspd = 0;
}

// Moving vertically
y += vspd;
 

The-any-Key

Member
The keyboard_check_pressed(vk_shift) will set key_dash to true in one step and then set it to false in the next steps. keyboard_check_pressed only detect when a key is pressed in one step. keyboard_check detect if a key is hold down in a step. keyboard_check_released detect when a key just released in one step.

When you press a keyboard keyboard_check_pressed will return true.
If the key still is held down in the next step keyboard_check will return true. But keyboard_check_pressed will return false (It only detect the pressed event not the hold down event).
If you release the key keyboard_check_released will return true. But keyboard_check return false. And keyboard_check_pressed return false.
In the next step all will return false. Even keyboard_check_released.

So:
Code:
var key_dash = keyboard_check(vk_shift);
 
X

xCrazyxSinner13x

Guest
The keyboard_check_pressed(vk_shift) will set key_dash to true in one step and then set it to false in the next steps. keyboard_check_pressed only detect when a key is pressed in one step. keyboard_check detect if a key is hold down in a step. keyboard_check_released detect when a key just released in one step.

When you press a keyboard keyboard_check_pressed will return true.
If the key still is held down in the next step keyboard_check will return true. But keyboard_check_pressed will return false (It only detect the pressed event not the hold down event).
If you release the key keyboard_check_released will return true. But keyboard_check return false. And keyboard_check_pressed return false.
In the next step all will return false. Even keyboard_check_released.

So:
Code:
var key_dash = keyboard_check(vk_shift);
i tried the code it now makes the character just run constantly till i like go of the shift key i was wonder would like a alarm help on keyboard pressed one or something but i am not sure how to implement it thoug i been stuck all day on ive tried many things but they all do the opposite thing i want it to do.
 

The-any-Key

Member
Ok. So the code:

Code:
// dash speed left
if(key_dash) and sprite_index = spr_player_left
{
hspd=spd*-4;
}

// dash speed left
if(key_dash) and sprite_index = spr_player_right
{
hspd=spd*+4;
}
Should run for a specific amount of time.

First set back:
Code:
var key_dash = keyboard_check_pressed(vk_shift);
In the create event add:
Code:
// Dash active
Dash_Active=false;
We will set this to true and the speed code will run when Dash_Active is true.

Ok change the speed code in step event:
Code:
if Dash_Active
{
    // dash speed left
    if sprite_index = spr_player_left
    {
        hspd=spd*-4;
    }

    // dash speed left
    if sprite_index = spr_player_right
    {
        hspd=spd*+4;
    }
}
else
{
    if key_dash and alarm[1]=-1
    {
        Dash_Active=true; // Set to run speed code
        alarm[0]=room_speed*0.5 // How long the dash works
        alarm[1]=room_speed*5 // Wait until dash again
    }
}
When Dash_Active is false and we press the dash key and the alarm[1] is -1 (default value when alarm is not set).
We set Dash_Active to true and start 2 alarms.
alarm 0 will reset Dash_Active back to false so it wont run the speed code anymore.
alarm 1 will just countdown until it set to -1 again.
If we press the dash key before alarm 1 is -1. It wont set Dash_Active to true. We must wait until alarm is done and counted down to -1 before we can hit the dash button again.

In alarm 0 event
Code:
Dash_Active=false;
In alarm 1 event
Code:
// Nothing, we can now dash again
// We can set this as clarification, but it is not needed
alarm[1]=-1
 
X

xCrazyxSinner13x

Guest
Ok. So the code:

Code:
// dash speed left
if(key_dash) and sprite_index = spr_player_left
{
hspd=spd*-4;
}

// dash speed left
if(key_dash) and sprite_index = spr_player_right
{
hspd=spd*+4;
}
Should run for a specific amount of time.

First set back:
Code:
var key_dash = keyboard_check_pressed(vk_shift);
In the create event add:
Code:
// Dash active
Dash_Active=false;
We will set this to true and the speed code will run when Dash_Active is true.

Ok change the speed code in step event:
Code:
if Dash_Active
{
    // dash speed left
    if sprite_index = spr_player_left
    {
        hspd=spd*-4;
    }

    // dash speed left
    if sprite_index = spr_player_right
    {
        hspd=spd*+4;
    }
}
else
{
    if key_dash and alarm[1]=-1
    {
        Dash_Active=true; // Set to run speed code
        alarm[0]=room_speed*0.5 // How long the dash works
        alarm[1]=room_speed*5 // Wait until dash again
    }
}
When Dash_Active is false and we press the dash key and the alarm[1] is -1 (default value when alarm is not set).
We set Dash_Active to true and start 2 alarms.
alarm 0 will reset Dash_Active back to false so it wont run the speed code anymore.
alarm 1 will just countdown until it set to -1 again.
If we press the dash key before alarm 1 is -1. It wont set Dash_Active to true. We must wait until alarm is done and counted down to -1 before we can hit the dash button again.

In alarm 0 event
Code:
Dash_Active=false;
In alarm 1 event
Code:
// Nothing, we can now dash again
// We can set this as clarification, but it is not needed
alarm[1]=-1
thanks man it worked is there any way i can repay u man
 
Top