Legacy GM Jumping and Falling sprites

M

MagicFool64

Guest
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?
 

curato

Member
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.
 
M

MagicFool64

Guest
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.
I used Cameron Penner's platform tutorial form programming collisions and commands
 
N

NeZvers

Guest
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;}
 
M

MagicFool64

Guest
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;}
Can you make a script example? Please
 

3dgeminis

Member
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}
 
N

NeZvers

Guest
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
    }
}
 
M

MagicFool64

Guest
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
    }
}
Do I have to write a grounded var in Create Event?
 
M

MagicFool64

Guest
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
    }
}
It works, thanks
 
Top