How to resolve a collision between two rectangles
Posted: Wed Dec 02, 2015 1:48 am
Disclaimer: This is all (PSEUDOCODE)
I have a Tile Map in an array like so
I then use a for loop to create an individual tile for each element in the array like so
Every tile has the same width and height and none of the tiles are moving.
While the player can move freely throughout the map without any fixed movement.
Now that I have covered some background I can continue with my actual problem. I'm having no issues detecting if there is a collision but with actually solving the collision and determining which side the collision was detected.
My current approach is similar to as follows
Then I use what is returned and proceed to actually solve the collision.
The method that returns what side is being intersected doesn't work as intended. I also do not know how to resolve the collision. Which is why I ask How to resolve a collision between two rectangles in a 2D grid?
http://stackoverflow.com/questions/3403 ... -a-2d-grid
I have a Tile Map in an array like so
Code: Select all
{0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0}
Code: Select all
newTile(x,y)
While the player can move freely throughout the map without any fixed movement.
Now that I have covered some background I can continue with my actual problem. I'm having no issues detecting if there is a collision but with actually solving the collision and determining which side the collision was detected.
My current approach is similar to as follows
Code: Select all
if(colliding(player, tile))
if(playerX + playerW >= tileX)
return rightSide
if(playerX <= tileX + tileW)
return leftSide
if(playerY + playerH >= tileY)
return bottomSide
if(playerY <= tileY + tileH)
return topSide
Code: Select all
if(checkSide() == rightSide)
// What now???
http://stackoverflow.com/questions/3403 ... -a-2d-grid