Page 1 of 2

Sliding Pixel Collision?

Posted: Mon Jul 26, 2021 6:32 am
by kicknbritt
Hey guys. I am putting the finishing touches on my games terrain collision system and I need some help.
Here is the situation:
Imagine a bunch of players with an x, y and direction running around a map.
The map consists of a texture holding terrain pixels.

For collision detection, I am using the players x and y to check if a specific position contains terrain.
Players can move around and collide with terrain but upon hitting a wall they just sort of freeze :( (they get stuck on pixels).

I need a way to make player-wall collision cause them to slide along terrain.
Does anyone know of any way to do this?

Re: Sliding Pixel Collision?

Posted: Mon Jul 26, 2021 7:11 am
by darkfrei
Not exactly what you want, but must be pretty close example:

Code: Select all

if angled_floor () then -- the floor is a ramp 45 or -45 degrees
	local sign = vx < 0 and -1 or 1 -- right moving gives positive value, left moving gives negative
	local t = tangent_of_ramp () -- gives 1 for 45 degrees and -1 for -45 degrees
	-- note that dy is inverted
	vy = sign*(-t)*vx -- vertical speed is the same as horizontal speed, but negative when the ramp has bottomleft-topright inclination.
end
Left tiles are "walkable", right tiles are "not walkable", but you can go through the bevels.

Re: Sliding Pixel Collision?

Posted: Mon Jul 26, 2021 4:26 pm
by kicknbritt
Sorry, maybe I should have specified the perspective is top-down.

I have tried to think of something but I can't find any way this would map directly to a top-down map but I could easily be wrong.

Re: Sliding Pixel Collision?

Posted: Mon Jul 26, 2021 5:03 pm
by ReFreezed
Before the game begins, calculate which corners should have slopes over them and put a "wedge" object or something there, and when players intersect with a wedge just handle the collision the same way as for axis-aligned walls, just at an angle.

Re: Sliding Pixel Collision?

Posted: Mon Jul 26, 2021 5:05 pm
by kicknbritt
Actually I was just thinking that. Trying to work something out right now

Re: Sliding Pixel Collision?

Posted: Mon Jul 26, 2021 5:48 pm
by kicknbritt
I don't think that approach will work either because I need the player to slide on terrain in the direction they are moving.
Also I would rather find a way without precomputing everything if possible.

I guess what I really need, is some kind of math that determines a movement direction upon collision.
Or maybe I can just cast rays upon collision and sort of octopus players around terrain. This might be expensive though...

Re: Sliding Pixel Collision?

Posted: Mon Jul 26, 2021 10:58 pm
by ReFreezed
Is this the functionality you want?
SmoothCornerCollisionsInTiledTopDownGame.love
(2.31 KiB) Downloaded 341 times

Re: Sliding Pixel Collision?

Posted: Tue Jul 27, 2021 3:13 am
by kicknbritt
Actually this might work. I think I misunderstood what you meant. Let me try to work in some sort of angular movement into the example.

Re: Sliding Pixel Collision?

Posted: Tue Jul 27, 2021 4:54 pm
by darkfrei
Youtube has very nice suggestions!
https://youtu.be/Isvs9OzX6Lk



solved vertical collision:
sloping-tiles-01.love
solved vertical collision
(3.99 KiB) Downloaded 149 times

Re: Sliding Pixel Collision?

Posted: Thu Jul 29, 2021 4:35 am
by kicknbritt
Sorry guys I have been insanely, insanely busy. I will try to get this worked on in a day or two.