Ceiling collision get's triggered on walls

I am looking into this game engine and I have come across a bug in the Pixel Line Platformer sample. When the player is moving in the direction of the wall but is already next to the wall and then attemps to jump jumping the ceiling collision get’s triggered. This obviously cuts the jump short.

The code used to detect if we collide with the ceiling on line 182 is

if normal.y < -0.7 then
	self.velocity.y = 0
end

I’m guessing that the problem is occurring because the player hits the bottom of a tile that constitutes the wall. I imagine this is a common problem but I didn’t really see anyone mentioning it and I apologize if I simply missed it but how would I go about fixing this.

Sorry for not replying to this issue sooner. Yes, it’s a false positive that can be eliminated by only caring about high normal values and removing small values. Something like this:

local NORMAL_THRESHOLD = 0.8

-- https://defold.com/manuals/physics/#resolving-kinematic-collisions
local function handle_obstacle_contact(self, normal, distance)
	-- don't care about anything but normals beyond the threshold
	-- we do this to eliminate false-positives such as ceiling hits when
	-- jumping next to a wall while moving into the wall
	if normal.y < NORMAL_THRESHOLD and normal.y > -NORMAL_THRESHOLD then
		normal.y = 0
	end
	if normal.x < NORMAL_THRESHOLD and normal.x > -NORMAL_THRESHOLD then
		normal.x = 0
	end
	-- update distance in case the normals have changed
	distance = distance * vmath.length(normal)

	-- continue with resolving collisions
	...
end
1 Like