N
nired360
Guest
Hi, am having a problem with tile collision and gravity in my 2d platformer i used the code from shaun spalding's video for tile collision and implemented gravity but whenever my character hits the floor, he starts bouncing non stop, it's driving me nuts, plz help.
Here's the code for vertical collision :
//vertical collision
if (vsp > 0) bbox_side = bbox_bottom else bbox_side = bbox_top;
p1 = tilemap_get_at_pixel(tilemap,bbox_right,bbox_side+vsp);
p2 = tilemap_get_at_pixel(tilemap,bbox_left,bbox_side+vsp);
if (p1 == 1) or (p2 == 1)
{
if (vsp > 0 ) y = y - (y mod tilesize) + (tilesize -1 ) - (bbox_bottom - y);
else y = y - (y mod tilesize) - (bbox_top - y);
vsp = 0;
}
y += vsp;
tilesize is 16x16 btw
Here's the code for vertical collision :
//vertical collision
if (vsp > 0) bbox_side = bbox_bottom else bbox_side = bbox_top;
p1 = tilemap_get_at_pixel(tilemap,bbox_right,bbox_side+vsp);
p2 = tilemap_get_at_pixel(tilemap,bbox_left,bbox_side+vsp);
if (p1 == 1) or (p2 == 1)
{
if (vsp > 0 ) y = y - (y mod tilesize) + (tilesize -1 ) - (bbox_bottom - y);
else y = y - (y mod tilesize) - (bbox_top - y);
vsp = 0;
}
y += vsp;
tilesize is 16x16 btw