I am working on a Terraria-like and I am having a simple issue with collision detection on the sides of blocks.
In this picture you can see that the player collision box is slighty inside that of the blocks. If the player holds the arrow towards the wall, it penetrates a bit further, but if released, eventually the player is pushed out of the wall and falls the rest of the way down. I am currently converting a Unity version of this skeleton of the game into Defold and I ran into this exact same issue with Unity. I solved it in Unity by using edge colliders, but I know that is not an option.
I assume I am somehow misusing the logic for collision detection provided here, or that it is missing necessary extra considerations for a tiled map. The code that handles this currently is as such:
if distance > 0 then
-- First, project the accumulated correction onto
-- the penetration vector
local proj = vmath.project(self.correction, normal * distance)
if proj < 1 then
-- Only care for projections that does not overshoot.
local compensation = (distance - distance * proj) * normal
-- Apply compensation
go.set_position(go.get_position() + compensation)
-- Accumulate correction done
self.correction = self.correction + compensation
end
end
In the end, it would also be nice to solve this problem by creating some kind of continual mesh around the nearby blocks, but is this possible with Defold? Is that what tilemaps and tilesources are supposed to accomplish for me? Thanks ahead of time!