Page 1 of 1

Bit of help with platformer collision detection

Posted: Wed Aug 22, 2018 3:07 pm
by Carracer12
Hey

So I recently tried getting back into a bit of coding, thought I'd try making a small platformer game and I'm having a bit of trouble with the collisions system. So I had a function to detect whether two objects are intersecting but this doesn't help me when I'm trying to make platforms at different heights to stand on. I have since deleted the collision function to try to come up with something new but have lost inspiration.

I've got a table called collideList which will hopefully hold all the platforms, they should be drawn in red (for testing). So all the images are drawn at a scale called worldScale based off the window size which should be around 5 for 1080p.

Thanks for any help in advance!

Re: Bit of help with platformer collision detection

Posted: Thu Aug 23, 2018 12:20 pm
by Link
You attempt to move the player to the desired position, check whether the position collides with anything, and adjust the position accordingly if a collision occurs (e.g. if player is falling downwards onto a platform, tweak the players position so they're standing on the platform). I wrote a more detailed response previously: viewtopic.php?f=4&t=85437&p=221891#p221891

There is a basic collision detection function in the Wiki, I presume you already have something similar: https://love2d.org/wiki/BoundingBox.lua

I don't know whether you're writing your own collision detection as a learning exercise, or simply trying to make a game. If the latter, I advise using an existing library for collision detection/response, such as https://github.com/kikito/bump.lua or the Physics module built into Love (which is more complex than bump).