Code: Select all
function CheckCollision(rect1, rect2)
local x1,y1,w1,h1 = rect1.x,rect1.y,rect1.width,rect1.height
local x2,y2,w2,h2 = rect2.x,rect2.y,rect2.width,rect2.height
return x1 < x2+w2 and
x2 < x1+w1 and
y1 < y2+h2 and
y2 < y1+h1
end
for some reason, when i decrease the y value of the player by increments of 0.1, some tiles will register collision exactly divisible by 8 (ei 288, 296, 304) etc but some tiles, specifically on the lower half of the map, will register the collision a decimal early (287.99999998) etc. I've ran checks on every block's x and y value and had them print if they were divisible by 8, and they are, which shows that it has nothing to do with the block's collision.
I don't understand where this inconsistency comes from, and i've checked every single value to make sure the position is correct. I think the issue might be a love2d-related error, or maybe the collision function is off. Anyways, here are some pictures of results that i got when changing the y by increments of 0.001

here is the y value i got for a block on the higher part of the map

y value for lower.