Bouncing Bug I wanna squash

So recently I decided to gut a game I have been working on for off/on a couple years. Started from scratch and am porting in code from the old one to the new one, one object at a time or as needed. So I can weed out the crap. Going great. BUT once I got the player movement code in this issue presented itself. When I run left/right the player rapidly cycles between a single pixel. See the gif below. This is the same code that works great in the other version but this version does not. Its baffling me. I have adjusted origins and removed this and that trying to find the culprit to no avail.

(hero Y) and (grounded) show what's occurring. It couses the vertically "vibrate" the character.
2021-02-15-11-02-14.gif

Here is the collision code.
GML:
// Horizontal Collision
if (place_meeting (x + hsp, y, allCollide))
{   
    yplus = 0;
    while (place_meeting(x+hsp,y-yplus,allCollide) && yplus <= abs(1*hsp)) yplus += 1;
    if place_meeting(x+hsp,y-yplus,allCollide)
    {
        while (!place_meeting(x + sign(hsp), y, allCollide))
        {
            x = x + sign(hsp);
        }
        hsp = 0;
    }
    else
    {
        y -= yplus;
    }
}
x  = x + hsp;

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

if (vsp != 0) grounded = false; else grounded = true;
 

Nidoking

Member
while (place_meeting(x+hsp,y-yplus,allCollide) && yplus <= abs(1*hsp)) yplus += 1;
I take it this is for climbing slopes? It looks like this is likely to leave yplus at 1 even when you're not moving (hsp is zero), giving you one pixel of upward movement that's then undone the next step. Maybe you should have yplus < abs (hsp) and see what happens. Doing 1* is meaningless but might also introduce some amount of floating point error.
 
I take it this is for climbing slopes? It looks like this is likely to leave yplus at 1 even when you're not moving (hsp is zero), giving you one pixel of upward movement that's then undone the next step. Maybe you should have yplus < abs (hsp) and see what happens. Doing 1* is meaningless but might also introduce some amount of floating point error.
I tried (just now) to change

while (place_meeting(x+hsp,y-yplus,allCollide) && yplus <= abs(1*hsp)) yplus += 1;

to

while (place_meeting(x+hsp,y-yplus,allCollide) && yplus < abs(hsp)) yplus += 1;

But it's still doing it. And I dont have slopes in my game. Whats perplexing is it works fine in the old file. And its the same code.
 

Nidoking

Member
Sounds like a job for the debugger, then. Look at stuff like your hsp and vsp values and see what's happening. Perhaps the "grounded" value is used somewhere else. I notice you have a "hovering" value that you haven't said anything about.
 
Yeah I need to learn how to actually USE the debugger. Im new to coding so I have no idea how to use it. I have run the game with the debugger but dont know whats different or how to use it effectively you know.
 

Nidoking

Member
The solution to the problem of being new to something and not knowing how to do it is to do it until you are no longer new. There are surely tutorials and/or videos that can teach you how to use the debugger.
 
Top