• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

tilemap collision "bouncing" issue

ive been having an issue where my player object keeps bouncing off the ceiling and floor of the tiles. i got the code from this guy on youtube, here is the link:
im new to programming so this could just be due to my lack of knowledge but here's what i tried:
i originally thought this issue was due to the gravity value on the player being a float but i tried solutions for it and none of them worked.
then i thought it could have something to do with my players sprites size since he says in the video to not have a bigger player sprite than your tiles so i figured i could find a work around, but nothing.
keep in mind my horizontal collision is completely fine, my vertical collision is the problem.
GML:
//trying float fix again
hsp += hsp_f;
vsp += vsp_f;

hsp_f = hsp - (floor(abs(hsp)) * sign(hsp));
hsp -= hsp_f;
vsp_f = vsp - (floor(abs(vsp)) * sign(vsp));
vsp -= vsp_f;

//Horizontal Collision
if (hsp > 0) bbox_side = bbox_right; else bbox_side = bbox_left;
p1 = tilemap_get_at_pixel(tilemap,bbox_side+hsp,bbox_top)
p2 = tilemap_get_at_pixel(tilemap,bbox_side+hsp,bbox_bottom)
if (p1 != 0) || (p2 != 0)
{
    if (hsp > 0) x = x - (x mod 12) + 11 - (bbox_right - x)
    else x = x - (x mod 12) - (bbox_left - x)
    hsp = 0;
}
x += hsp;

//Vertical Collision
if (vsp >= 0) bbox_side = bbox_bottom; else bbox_side = bbox_top;
p1 = tilemap_get_at_pixel(tilemap,bbox_left,bbox_side+vsp)
p2 = tilemap_get_at_pixel(tilemap,bbox_right,bbox_side+vsp)
if (p1 != 0) || (p2 != 0)
{
    y = (y + vsp & ~7) + y + 7 * (vsp > 0) - bbox_side;
    vsp = 0;
}
y += vsp;
my gravity value is set to 0.1 by the way

if anyone can help try and figure this out i would appreciate it a lot
 
i think i might've managed to figured it out myself i fixed it bouncing by removing

y = (y + vsp & ~7) + y + 7 * (vsp > 0) - bbox_side;

and then it just worked a bit strange but i can kinda see why.
instead of going through that process before where it was setting it above/below the tile it just goes through this:

hsp += hsp_f;
vsp += vsp_f;

hsp_f = hsp - (floor(abs(hsp)) * sign(hsp));
hsp -= hsp_f;
vsp_f = vsp - (floor(abs(vsp)) * sign(vsp));
vsp -= vsp_f;

and lands completely fine. there is one thing tho, when i jump, at max height i kinda float in the air for a sec, i kinda fixed this by replacing floor to round.
dont do ceil tho because it will bounce instead of snapping properly.
 
Top