GMS 2 Detect small or high jump

Discussion in 'Programming' started by MuddyMuddy, Jan 15, 2020.

  1. MuddyMuddy

    MuddyMuddy Member

    Joined:
    Mar 2, 2017
    Posts:
    184
    Hi -

    How might I do a small hop if the keyboard is tapped - but go into a full jump if held just slightly longer?

    This is my current code for jumping - I would like to keep 'keyboard_check_pressed' so that you have to re-press jump to jump again, not just hold the key.

    Code:
    if !place_meeting(x,y+1,o_solid){
        if vspd <= max_vspd{vspd += grav;}else{
        vspd = max_vspd;
            }
    }else{
    if keyboard_check_pressed(vk_space){
    vspd -= jumpheight;
    }
    }

    I believe it is the 'vspd -= jumpheight;' part that I should be looking at?

    Many thanks
     
  2. Adjud

    Adjud Member

    Joined:
    Sep 11, 2017
    Posts:
    73
    you can base you jump height off a counter, im not great with code but i would set a max count number, so as the keyboard is held it will count up to the max number and whatever the count reached will determine how high the character jumps, if it reaches max jump it jumps the highest etc...
     
  3. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,192
    A very simple way is with something like this:

    Code:
    
    if (action_released) {
         vsp = max(vsp, jump_speed / 4);
    }
    
    
    Where action_released is your check for the release of whatever button makes the jump. Without seeing all your player's code I can't say for sure, but that would probably go inside of the your if statement:

    Code:
    
    if !place_meeting(x,y+1,o_solid){
        if (keyboard_check_released(vk_space)) {
            vsp = max(vsp, jump_speed / 4);
        }
        if vspd <= max_vspd {
            vspd += grav;
        } else {
            vspd = max_vspd;
        }
    } else {
        if keyboard_check_pressed(vk_space) {
            vspd -= jumpheight;
        }
    }
    
    
     
  4. MuddyMuddy

    MuddyMuddy Member

    Joined:
    Mar 2, 2017
    Posts:
    184
    @samspade Thanks that works great - is there a way to only have 2 hights with this? a max and a half of max ?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice