Hey guys!
I’m starting to make a simple 2D platformer and I’m not sure how to handle collisions. I get the basic idea: entities and tiles have bounding boxes and checking if two boxes overlap is basic math. But once I know entity A and tile B overlap, I can’t think of a way to move entity A to the edge of tile B so they don’t overlap without an if chain checking for each direction. And then there are special cases, such as tiles you can jump onto from below so I’d need another if statement to check against those and if the entity is moving up when that collision happens. How do you guys/gals go about doing this cleanly, without a dozen if statements and state checking? What is generally done to resolve collisions in a basic platformer? I tried searching the forums and googling solutions but all the articles I found focused more simply detecting if two bounding boxes overlap rather than what to do after that.
I feel like there should be a simple solution but I’m thinking about this too much and can’t think of a way to handle this without messy code that couples a dozen objects together.