Original Post
So, in a glOrtho'd 2D-esque side-scroller, I'm trying to get bullet vs. wall collision detection. The problem is as follows: bx is the bullet's x, by the bullet's y tx is the tile's x, ty is the tile's y size is the width AND height of the tile (both are the same) bsize is the width AND height of the bullet (both are the same) For hitting the top of the wall, my collision is like this Left of the wall: Bottom of the wall: Right of the wall: However, for example, the bullet is hitting the left of the wall, the IF statement matches the same as the bottom of the wall, because all parameters match for both! So there isn't a way, in this method, I can check which side it's truly hitting. So I need a new method. I tried checking each corner of the bullet, and deciding things like "If the top right and bottom right corners are in the wall, it's hitting the left side", but it doesn't work in that instance where all 4 corners are in the wall (it happens: the bullet's x and y is increased by a velocity every loop, so if it happens to put all 4 corners inside than there isn't anything I can do about it) So any help? >.<
if(bx > tx && bx < tx + size && by + bsize > ty && by + bsize < ty + bsize) { collision stuff; }
/*If bullet x is in the tile, and the bottom of the bullet is more than the top of the wall and less than the top of the wall + bullet size*/
if(bx + bsize > tx && bx + bsize < tx + bsize && by > ty && by < ty + size) { collision stuff; }
if(bx > tx && bx < tx + size && by < ty + size && by > ty + size - bsize) { collision stuff; }
if(bx < tx + size && bx > tx + size - bsize && by > ty && by < ty + size) { collision stuff; }