fix: better collisions

Fixes #83
This commit is contained in:
Kazhnuz 2021-04-11 09:57:44 +02:00
parent cd0190f065
commit 705d07abb6

View file

@ -106,13 +106,25 @@ function Hitbox2D:checkCollision(dx, dy, filter)
local nx, ny = self.ox + dx, self.oy + dy
if (self.owner.useTileCollision and self.world.map.supportTileCollision) then
if (self:checkTileCollision(nx, self.y)) then
nx = self.x + 1
nx = math.floor(nx / 16) * 16
nx = self.x
local relx = dx - self.x
for i = 1, math.ceil(math.abs(relx)), 1 do
local nnx = self.x + i * utils.math.sign(relx)
if (not self:checkTileCollision(nnx, self.y)) then
nx = nnx
end
end
self.owner.xsp = 0
end
if (self:checkTileCollision(self.x, ny)) then
ny = self.y + 1
ny = math.floor(ny / 16) * 16
ny = self.y
local rely = dy - self.y
for i = 1, math.ceil(math.abs(rely)), 1 do
local nny = self.y + i * utils.math.sign(rely)
if (not self:checkTileCollision(self.x, nny)) then
ny = nny
end
end
self.owner.ysp = 0
end
end