Page 2 of 2

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

Posted: Mon Feb 26, 2024 11:15 am
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.

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

Posted: Mon Feb 26, 2024 3:33 pm
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!