Catching on tiled wall collision boxes

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!

Try changing from a box to a sphere for the player collision object. Or check Platypus from the Asset Portal.

3 Likes

Both of those solve the problem! Sadly, switching to the sphere provided a new issue where if I start to fall off an edge, I can move right back onto it.

I will likely try out platypus, for it seems to support many of the features I will eventually need anyways, such as wall and double jumps. Thanks!

Platypus works wonderfully! Thanks!

Great! Happy to hear that! Let me know if you run into any problems with the lib or have any feature requests!

1 Like