Legacy GM [SOLVED] Animation glitch when descending slopes

A

AtomicToilet

Guest
Hola!

First a caveat: I've eyeballed similar threads on here and gather I need to somehow tell the Player object to ignore very small changes in height (as this is what's triggering the change to the 'falling' animation when they descend), but I'm not sure how I can implement this with my particular code. Any suggestions are gratefully received!

Here's (I think) the most relevant/important parts of my move script:

Code:
if (place_meeting(x,y+1,obj_wall))
{
    in_air = false;
    vsp = key_up * -jumpspeed
}

else if (!place_meeting(x,y+1,obj_wall))
{
    in_air = true;
}

//Horizontal Collision
if place_meeting(x+hsp,y,obj_wall)
{
    yplus = 0;
    while (place_meeting(x+hsp,y-yplus,obj_wall) && yplus <=abs (1*hsp)) yplus += 1;
    if place_meeting(x+hsp,y-yplus,obj_wall)
    {
    while (!place_meeting(x+sign(hsp),y,obj_wall))
    x += sign(hsp);
    hsp = 0;
    }
    else
    {
    y -= yplus
    }
}
x += hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
   while(!place_meeting(x,y+sign(vsp),obj_wall))
   {
       y += sign(vsp);
       in_air = true;
   }
   vsp = 0;
}
y += vsp;
And in case the answer's as simple as tweaking my animation code, here's that:

Code:
if (in_air == true)

{
sprite_index = spr_player_jump;
image_speed = 0;
image_index = (y > yprevious);
}

else if (in_air == false) && (xprevious !=x)
{
sprite_index = spr_player_run;
image_speed = .4;
}

else
{
sprite_index = spr_player_idle;
image_speed = .05;
}
 
D

Dandysius

Guest
You want us to fix falling animation, but we do not know what you mean by falling animation. is it spr_player_idle?
 

Simon Gust

Member
Try checking for being in the air after you've updated your position.
Code:
if (!in_air) // if on the ground
{
    vsp = key_up * -jumpspeed
}

//Horizontal Collision
if place_meeting(x+hsp,y,obj_wall)
{
    yplus = 0;
    while (place_meeting(x+hsp,y-yplus,obj_wall) && yplus <=abs (1*hsp)) yplus += 1;
    if place_meeting(x+hsp,y-yplus,obj_wall)
    {
       while (!place_meeting(x+sign(hsp),y,obj_wall))
       {
          x += sign(hsp);
       }
       hsp = 0;
    }
    else
    {
       y -= yplus
    }
}
x += hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
   while(!place_meeting(x,y+sign(vsp),obj_wall))
   {
       y += sign(vsp);
   }
   vsp = 0;
}
y += vsp;

// check if on the ground or not after collision
in_air = place_meeting(x, y+1, obj_wall);
 
A

AtomicToilet

Guest
Cheers for the replies!

Sorry Dandysius - I mean it changes/glitches from the run animation to the jump animation (wherein frame 0 is jumping up, frame 1 is falling, so the glitch momentarily displays frame 1).

Simon, cheers for the code suggestion - but it makes everything wonky.

I've managed to make a couple of gifs so you lot can see what I mean:


This is my original code, with the animation glitch:
Runner-2018-08-31-13-15-13-71.gif

and with Simon's code:

Runner-2018-08-31-13-23-29-03.gif
 

Simon Gust

Member
hm weird,
is your animation code before your collision code by chance?
Try extending the range for checking the in-air collision
Code:
in_air = place_meeting(x, y+2, obj_wall);
 

Bentley

Member
I didn't see anything in your code to handle down slopes. So your character is falling every time he reaches the edge of a slope. So "in_air" is set to true when it shouldn't be, as you'd want your player to walk down slopes not walk, fall, walk, fall, etc.
 

Joe Ellis

Member
You can do a thing similar to the code for going up a slope, checking if down a few pixels has a collision, and if so, move the player's y to touch the floor, rather than being "in_air",
But only do this if its not "in_air" to begin with (to stop early snapping to the floor when landing from a jump)
 
A

AtomicToilet

Guest
Cheers folks! I'll have a look at the code with your suggestions in mind and see if I can it to work :cool:
 
S

spoonsinbunnies

Guest
my solution would be to simply make something similar to xprevious and yprevious but for in the air this is literally as simple as
create

in_air_previous=1

and the beggning of your step event step

in_air_previous=in_air

the last step would be in your check to change to the falling sprite make sure that both are true, what that does is make a buffer of falling for one step before changing so if your hill isn't too steep this should in theory work fine, its not the most elegant solution or a proper fix, just a very easy workaround seeing as doing otherwise requires a check of the slope of the ground which goes into some mid algebra. Apologies to the admins for not using the coding brackets id rather not back out and go all the way out to find it, might edit it in.
 
Last edited by a moderator:
A

AtomicToilet

Guest
Hola folks! Fixed it - cheers for the suggestions! I put this code between the horizontal (slope) movement and normal vertical movement:

Code:
//Down slopes
if !place_meeting(x,y,obj_wall) && vsp >= 0 && place_meeting(x,y+2+abs(hsp),obj_wall)
{
while(!place_meeting(x,y+1,obj_wall))
{
y += 1;
}
}
I've still got the weird animation glitch like in the second gif up there ^ but I'm pretty sure I fixed that once but forgot to save it :rolleyes: so it shouldn't be difficult!

edit: aaaannddd solved the weird animation glitch in the second gif: I simply changed all my 'in_air' variables to 'on_ground' and then all the 'true' ones to 'false' eg:


Code:
if (on_ground == false)

{
sprite_index = spr_player_jump;
image_speed = 0;
image_index = (y > yprevious);
}

else if (on_ground == true) && (xprevious !=x)
{
sprite_index = spr_player_run;
image_speed = .4;
}

else
{
sprite_index = spr_player_idle;
image_speed = .05;
}


if hsp > 1
image_xscale = 1;
if hsp < 0
image_xscale = -1;
 
Last edited by a moderator:
Top