GM:S 1.4 Jumping and Falling sprites

Discussion in 'Programming' started by MagicFool64, Jul 11, 2019 at 9:21 PM.

  1. MagicFool64

    MagicFool64 Member

    Joined:
    Feb 3, 2019
    Posts:
    39
    I want to make my character to change sprites when jumps and/or falls, in a platformer game. Do you know a good script?
    I use this script:
    if vspeed < 0
    sprite_index = spr_jump
    else if vspeed > 0
    sprite_index = spr_fall
    else if vspeed = 0
    sprite_index = spr_stand

    But gives me a bug: when the character is in the air, his sprite turns for 1 second in the standing sprite. And then turns into the falling sprite when falls. Do you know a better script?
     
  2. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    219
    Depending on how you are handling collisions, look under to see if the there is something under it to stand on when jumping (object or tile) then you just keep with the jump sprite until there is something there then you return to stand.
     
  3. MagicFool64

    MagicFool64 Member

    Joined:
    Feb 3, 2019
    Posts:
    39
    I used Cameron Penner's platform tutorial form programming collisions and commands
     
  4. NeZvers

    NeZvers Member

    Joined:
    Mar 24, 2018
    Posts:
    317
    at the very top of jumping your character will get around vspeed = 0, so you need to all that decoupled with something if (!grounded){ //code;}
     
  5. MagicFool64

    MagicFool64 Member

    Joined:
    Feb 3, 2019
    Posts:
    39
    Can you make a script example? Please
     
  6. 3dgeminis

    3dgeminis Member

    Joined:
    Jun 21, 2016
    Posts:
    119
    You must add another condition when switching to the spr_stand sprite, in addition to the vertical velocity being 0, it has to be on the ground.
    Code:
    if ( vspeed=0 and place_meeting(x,y+1,obj_ground) ) {sprite_index=spr_stand}
     
  7. NeZvers

    NeZvers Member

    Joined:
    Mar 24, 2018
    Posts:
    317
    Code:
    if(plaxe_meeting(x,y+1,oSolid)){
        grounded = true
    }else{
        grounded = false
    }
    
    if(grounded){                   //you need to check if player is on the ground befor this
        sprite_index = spr_stand
    } else {
        if(vspeed<0){               //going up
            sprite_index = spr_jump
        }else{                      //going down
            sprite_index = spr_fall
        }
    }
    
     
  8. MagicFool64

    MagicFool64 Member

    Joined:
    Feb 3, 2019
    Posts:
    39
    Do I have to write a grounded var in Create Event?
     
  9. MagicFool64

    MagicFool64 Member

    Joined:
    Feb 3, 2019
    Posts:
    39
    It works, thanks
     
    NeZvers likes this.

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