1
General / AA unit square collisions with a grid of AA unit squares
« on: August 06, 2023, 01:15:17 am »
this seems really simple, and it probably is, but as a beginner with the c++ language and SFML, I'm having a hard time figuring this out.
I have a player, that is a square, one unit by one unit. I have a grid that is my map, that is a grid of squares, each one unit by one unit. The problem comes from the fact that I can't just check for collisions with every box in the map, as my map is 2000x900, and possibly larger. What I was doing was finding the block each vertex of my player was in, and checking if that block was empty or not. the problem with this method though was that there was glitchy behaviour, holding jump and to the right on a wall to the right of the player would result in the player getting stuck, while holding jump and left on a wall to the left would rocket the player upwards. in short, this method was inconsistent and ugly.
I'm wondering if there's any simpler methods? a pseudocode example or simple explanation would be best. the code is quite long, and creating a minimum example would still be large, but if you need the code I can send it.
I have a player, that is a square, one unit by one unit. I have a grid that is my map, that is a grid of squares, each one unit by one unit. The problem comes from the fact that I can't just check for collisions with every box in the map, as my map is 2000x900, and possibly larger. What I was doing was finding the block each vertex of my player was in, and checking if that block was empty or not. the problem with this method though was that there was glitchy behaviour, holding jump and to the right on a wall to the right of the player would result in the player getting stuck, while holding jump and left on a wall to the left would rocket the player upwards. in short, this method was inconsistent and ugly.
I'm wondering if there's any simpler methods? a pseudocode example or simple explanation would be best. the code is quite long, and creating a minimum example would still be large, but if you need the code I can send it.