From 705d07abb660887e2ec4bcd8ea470b26a51d599e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 11 Apr 2021 09:57:44 +0200 Subject: [PATCH] fix: better collisions Fixes #83 --- .../modules/world/actors/utils/hitbox2D.lua | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/sonic-radiance.love/core/modules/world/actors/utils/hitbox2D.lua b/sonic-radiance.love/core/modules/world/actors/utils/hitbox2D.lua index d661eba..680eab6 100644 --- a/sonic-radiance.love/core/modules/world/actors/utils/hitbox2D.lua +++ b/sonic-radiance.love/core/modules/world/actors/utils/hitbox2D.lua @@ -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