P
polymorphic_ nw
Guest
I'm a bit embarrassed that I don't see the issue with this code, but I feel as if I'm missing something, as this code should work regardless of the sprite size. I'm specifically having issues with the vertical collision, so I'll post that, though I'm not sure if the horizontal is working either. It's for a sidescroller. The player just falls through the floor.
global.tile_size was changed from 32 to 16. The sprites for all the player states were changed as well, and their collision masks have all been redrawn to be the same for every sprite. It seems the collision code triggers before it actually hits the ground, which indicates the bounding box might be triggering incorrectly. Anyone see any obvious errors?
Code:
//vertical collision
var side;
//determine which side to test
if (vsp > 0) side = bbox_bottom;
else side = bbox_top;
//check top and bottom of side
var t1 = tilemap_get_at_pixel(global.map, bbox_left, side + vsp);
var t2 = tilemap_get_at_pixel(global.map, bbox_right, side + vsp);
var t3 = tilemap_get_at_pixel(global.map, bbox_left, bbox_bottom)
var t4 = tilemap_get_at_pixel(global.map, bbox_right, bbox_bottom)
if (t1 != VOID and (((vsp > 0 or t1 != PLATFORM)) and t3 != PLATFORM) or (t1 == SOLID and t3 == PLATFORM)) or
(t2 != VOID and (((vsp > 0 or t2 != PLATFORM)) and t4 != PLATFORM) or (t2 == SOLID and t4 == PLATFORM)) {
//collision found
if (vsp > 0) y = y - (y mod global.tile_size) + global.tile_size - 1 - (side-y);
else y = y - (y mod global.tile_size) - (side - y);
vsp = 0;
}