GML Cannot Figure out Sprinting

I'm using a weird system for movement in order to do wall jumping with deceleration to prevent wall climbing, but due to that I can't seem to figure out how to do a sprint mechanic. I've tried setting the hsp value, and adding to the hsp value. If anyone can help, i'd like to bind sprinting to Lshift

Create Event:
Code:
hsp = 0;
vsp = 0;
hsp_frac = 0;
vsp_frac = 0;

hsp_acc = 1;
hsp_fric_ground = 0.50;
hsp_fric_air = 0.5;
hsp_walk = 4;
hsp_wjump = 4;

vsp_jump = -9
vsp_max = 10;
vsp_wjump = -8;
vsp_max_wall = 8;

onground = false;
onwall = 0;

grv = 0.3;
grv_wall = 0.1;

jumpbuffer = 0;
walljumpdelay = 0;
walljumpdelay_max = 17;

Step Event:

Code:
key_left = keyboard_check_direct(vk_left);
key_right = keyboard_check_direct(vk_right);
key_jump = keyboard_check_direct(vk_up);

//Walk Animation
if (key_right)
{
sprite_index = spr_player_anim;
}
if (keyboard_check_released(vk_right))
{
    sprite_index = spr_player;
}
if (key_left)
{
sprite_index = spr_player_anim;
}
if (keyboard_check_released(vk_left))
{
    sprite_index = spr_player;
}

//calc horizontal movement
walljumpdelay = max(walljumpdelay-1,0);
if (walljumpdelay == 0)
{
var dir = key_right - key_left;
hsp += dir * hsp_acc;
if (dir ==0) {
    var hsp_fric_final = hsp_fric_air;
    hsp = Approach(hsp,0,hsp_fric_final);
}
hsp = clamp(hsp,-hsp_walk,hsp_walk);
}
//Wall Climb
if (onwall != 0) && (!onground) && (key_jump)
{
    //Wall Jump
    walljumpdelay = 17;
    
    hsp = -onwall * hsp_wjump;
    vsp = vsp_wjump;
    
    hsp_frac = 0;
    vsp_frac = 0;
}

//calc vertical movement
var grv_final = grv;
var vsp_max_final = vsp_max;
if (onwall != 0) && (vsp < 0)
{
    grv_final = grv_wall;
    vsp_max_final = vsp_max_wall;
}
vsp += grv_final;
vsp = clamp(vsp,-vsp_max_final,vsp_max_final);

//ground jump
if (jumpbuffer > 0)
{
    jumpbuffer--;
    if (key_jump)
    {
        jumpbuffer = 0;
        vsp = vsp_jump;
        vsp_frac = 0;
    }
}
vsp = clamp(vsp,-vsp_max,vsp_max);

//dump fractions and get final integer speeds
hsp += hsp_frac;
vsp += vsp_frac
vsp_frac = frac(vsp);
hsp_frac = frac(hsp);
hsp -= hsp_frac;
vsp -= vsp_frac;

//horizontal collision
if (place_meeting(x+hsp,y,obj_Ground)) {
    var onepixel = sign(hsp);
    while(!place_meeting(x+onepixel,y,obj_Ground)) x += onepixel;
    hsp = 0;
    hsp_frac = 0;
}

//horizontal move
x += hsp;


//vertical collision
if (place_meeting(x,y+vsp,obj_Ground)) {
    var onepixel = sign(vsp);
    while(!place_meeting(x,y+onepixel,obj_Ground)) y += onepixel;
    vsp = 0;
    vsp_frac = 0;
}

//vertical move
y += vsp;

if (keyboard_check(vk_down))
{
    vsp = 10;
    sprite_index = spr_playerDuck;
}

if (keyboard_check_released(vk_down))
{
    sprite_index = spr_player
}
//calc current status
onground = place_meeting(x,y+1,obj_Ground);
onwall = place_meeting(x+1,y,obj_Ground) - place_meeting(x-1,y,obj_Ground);
if (onground) jumpbuffer = 6;
 

Simon Gust

Member
You are clamping your hsp to hsp_walk and -hsp_walk, if you want to sprint, you should lift that Limit to something greater than hsp_walk, something like hsp_run which you could set to 6 for example.
 
Top