I'm having trouble with 2D collision detection. My trouble isn't detecting a collision but doing something after a collision has been detected. I'm trying to keep the player from passing thru the other character but when they collide my player gets stuck. He can move the direction backwards that he came from when colliding but he can't move the perpendicular directions. For example if you run the player into the right side of the other character you can't move up or down you have to move left to get unstuck. I store the map and player positions after each frame and when I detect a collision I move the player back to the last position but something isn't working. My tile collision is working great but I'm having so much trouble with sprites. If anyone could take a look at my code below and offer any help it would be most appreciated. I searched collision detection in the forums but couldn't find anything useful. Thanks.
function storePositions()
`store map and player positions from previous frame
`store map's current x and y position
OldMapx = mapx
OldMapy = mapy
`store player's current x and y position
OldX1 = player.posX
OldY1 = player.posY
endfunction
function checkSpritecollision()
`Get edges of sprites for collision detection
global x1
global x2
global y1
global y2
x1 = player.posX + sprite width(player.spriteid)
x2 = man1.posX + sprite width(man1.spriteid)
y1 = player.posY + sprite height(player.spriteid)
y2 = man1.posY + sprite height(man1.spriteid)
`Check to see if sprites collide
if sprite hit(player.spriteid, man1.spriteid) = 1
`Keep player position from overlapping man1
if x1 > man1.posX and player.posX < x2 then player.posX = oldX1 : mapx = OldMapX
if y1 > man1.posY and player.posY < y2 then player.posY = oldY1 : mapy = OldMapY
endif
endfunction