netoxinaa
Member
I'm trying to add tile collisions into my game, but it won't work with the sprite I want the player to have. I made many tests but nothing worked, until I changed the sprite to be just a square 32x32, then it worked right! But I don't get why, since the code uses bounding boxes so I'm sure every sprite would have to function correctly.
My tiles are 16x16
Here's the code ( I use Shaun's tutorial) :
Also I'm using his method for removing decimals from the vSpeed so the player just moves in integers and doesn't do the "bouncing" effect.
My tiles are 16x16
Here's the code ( I use Shaun's tutorial) :
GML:
var bbox_side;
//HORIZONTAL
if (hSpeed > 0) bbox_side = bbox_right; else bbox_side = bbox_left;
if (tilemap_get_at_pixel(global.collisionMap, bbox_side + hSpeed, bbox_top) != 0
|| tilemap_get_at_pixel(global.collisionMap, bbox_side + hSpeed, bbox_bottom) != 0)
{
if (vSpeed > 0) x = x - (x mod TILE_SIZE) + 15 - (bbox_right - x);
else x = x - (x mod TILE_SIZE) - (bbox_left - x);
hSpeed = 0;
}
//VERTICAL
if (vSpeed > 0) bbox_side = bbox_bottom; else bbox_side = bbox_top;
if (tilemap_get_at_pixel(global.collisionMap, bbox_right, bbox_side + vSpeedFinal) != 0
|| tilemap_get_at_pixel(global.collisionMap, bbox_left, bbox_side + vSpeedFinal) != 0)
{
if (vSpeed = 0) y = y - (y mod TILE_SIZE) + 15 - (bbox_bottom - y);
else y = y - (y mod TILE_SIZE) - (bbox_top - y);
vSpeed = 0;
vSpeedF = 0;
vSpeedFinal = 0;
}