Need some help for my collision system

#1

This is probably the last struggle for my True Tile Collision. Since I want to get rid of any intervention of built-in physics but needed some collision checking for moving platform objects. So I created my collision check (separated axis collision). I need some guesses what’s might be off.
Problem is when the platform moves and collides with the player.

--Platform x & y is on top left corner
function player_on_platform(inst) --check if player is one pixel above
	inst.carry = collision_check_plat2play(inst, inst.POS + vmath.vector3(0,1,0)) --Check if player is on top and save their id
end
function h_moving_plat(inst,dt)
	local x = inst.POS.x
	--dcos and dsin are converted to work with degrees
	local dx = dcos(inst.time * 360 +(360*inst.offset.x)) * inst.radius.x
	inst.POS.x = inst.center.x + dx
	inst.spd.x = inst.POS.x -x														--Movement speed to check in collision
	if inst.carry~=nil then
		inst.carry.POS.x = inst.carry.POS.x + inst.spd.x
	end
end
function h_collision_plat2play(inst)													--platform against player
	local hsp = inst.spd.x
	if hsp~=0 then
		local player = collision_check_plat2play(inst, inst.POS)
		if player~=nil then
			if hsp>0 then
				player.POS.x = inst.POS.x + inst.width - player.hitbox_l
			elseif hsp<0 then
				player.POS.x = inst.POS.x - player.hitbox_r
			end
		end
	end
end
function v_moving_plat(inst,dt)
	local y = inst.POS.y
	local dy = dsin(inst.time * 360 +(360*inst.offset.y)) * inst.radius.y
	inst.POS.y = inst.center.y + dy
	inst.spd.y = inst.POS.y -y														--Movement speed to check in collision
	if inst.carry~=nil then
		inst.carry.POS.y = inst.carry.POS.y + inst.spd.y
	end
end
function v_collision_plat2play(inst)													--platform against player
	local vsp = inst.spd.y
	if vsp~=0 then
		local player = collision_check_plat2play(inst, inst.POS)
		if player~=nil then
			if vsp<0 then
				player.POS.y = inst.POS.y - inst.height - player.hitbox_t
			elseif vsp>0 then
				player.POS.y = inst.POS.y - player.hitbox_b
			end
		end
	end
end

Added project if interested to look closer.
TileCollisionPlatformer.zip (153.1 KB)
P.S. I’m amazed how small size the project is.

0 Likes

True Tile Collision
#2

No idea really. Hard to tell without really digging in to the logic and the code, and you’re probably the expert and best suited to solve the problem! Add print() statements or set breakpoints. Enable physics debug.

0 Likes

#3

it’s really simple logic:
move
if it is collided with player snap player to the according side.

It seems that the bigger movement speed the bigger loss in precision (less than player needs to be pushed back)

0 Likes

#4

In the video it looks like it’s lagging behind by one frame, is that the issue you’re talking about?

0 Likes

#5

It’s not lagging frame behind, but it’s positioned in wrong spot. It’s like inst.spd has less distance than it should be.

Edit: Actually, that may be possible. Although player is re-positioned at the same time platform is re-positioned.
Edit: You are right. Player was after platform in level collection and putting player before fixed that squishing inside a platform. Still sometimes false collision happens and I need to find why.

0 Likes