I can never seem to get this right, well polished at least. I'm creating a top down game in XNA, and collision has always been an issue for me to do properly. Detecting collision is fine, but resolving it is where I get messed up.
My approach so far:
- Check for collisionLoop through rectangles polled by a quad tree
- check if collision is foundthese rectangles intersect with the player
- if yes then immediately set their position outsideundo the tilevelocity that we just applied to the player
- if no then do nothing
However thisThis approach is very jittery and corners work poorly at bestless than ideal but it's close, I'm trying to allow players to move along the wall even if they're applying the force on the wall. If
For example: if the pushplayer collides against the tile while slidinga vertical wall, they should be able to move up and down even if they are still trying to move left/right.
I can't seem to find a good way to do this. Maybe I'm overthinking, but I tried doing vector subtraction on the sprite gets jitterycentre's of the player and tile and seeing where the vector pointed. But that didn't give me much helpful information. I tried seeing if it was the x-axis or y-axis that was colliding but that didn't work as wellthe player is bigger than the tiles.
Is there any best practices when working with collisiona way to find which axis is colliding so I can undo velocity on that specific axis?