Ok, so I am working on a game, and I found that my opponents do not like my collision detection, which works great for my player. After a little debugging, I found out about this because my enemies are bigger than my tiles, while my player is smaller than my tiles.
Now I need to be able to make big enemies and bosses, so this just will not happen. so I need to figure out the best way to check for collision detection. Here's how I do it now:
up and down:
if((enemy.left > tile.left && enemy.left < tile.right || enemy.right > tile.left && enemy.right < tile.right) && enemy.top < tile.bottom && enemy.bottom > tile.top){
//collision
}
left and right:
if((enemy.top > tile.top && enemy.top < tile.bottom || enemy.bottom > tile.top && enemy.bottom < tile.bottom) && enemy.left < tile.right && enemy.right > tile.left){
//colision
}
source
share