Trying to figure out collision with tiles in platformer game

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: Trying to figure out collision with tiles in platformer game

Post by darkfrei »

waffleturtle wrote: Sun Feb 25, 2024 5:01 am Thanks! I'll keep it in mind to not fret too much over optimization at this stage!

I got something sort of working now. It's still a bit wonky but at least going in the right direction now.

I ended up checking the direction of the player velocity and then test the closest two tiles towards that direction and applying a pushback based on player's world coordinates vs the tiles grid-position, if the player would end up inside the tile.

So I went with tile-based for the collision map for the world itself. But I think I will use a system more similar to what you describe for the objects in the world interacting with each other though!

Next on my list to think about is probably
- Slope-tiles
- Enemies walking around in the level using the same tile-based collision system the player does

Will see if I figure anything out there!
You can start with point-to-slope collision: viewtopic.php?p=255011#p255011
Than you can check all 4 points of your rectangles to check that the collision was true.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
waffleturtle
Prole
Posts: 6
Joined: Sun Feb 18, 2024 9:56 pm

Re: Trying to figure out collision with tiles in platformer game

Post by waffleturtle »

darkfrei wrote: Mon Feb 26, 2024 11:15 am You can start with point-to-slope collision: viewtopic.php?p=255011#p255011
Than you can check all 4 points of your rectangles to check that the collision was true.
That looks neat! I'll keep that thread bookmarked for future reference :)

I figured I would try keep it very simple for this first little game though. Coincidentally I was gonna go in the direction of the Platformer guide that you have in your signature (the MMX type). Though not exactly like it: I figured I could check where on the x-axis the player is and compare with the slope tile's x-position then offset the players y-position by that difference.

ex: if player is half-way through the slope tile then they would be offset by 16 pixels.

Downside of course is that I'll be stuck with a fixed degree value and I'd probably have to make a slope tile for each direction. But a 45 degree slope is a start I think!
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot], zorg and 3 guests