Porchinski
Member
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.
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 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;
if anyone can help try and figure this out i would appreciate it a lot