hi, i have written some code for my game's tile-player collision, but i sometimes get teleported when touching a side of the tile. i don't know if i am going to the right direction here, although the collision works... somewhat. any help on how to make a fully working collision would be much appreciated.
Code:void collides() { top = (player->y() - 0) / 32; bottom = (player->y() + player->height() + 32) / 32; left = (player->x() - 0) / 32; right = (player->x() + player->width() + 32) / 32; for (int my = top; my < bottom; my++) { for (int mx = left; mx < right; mx++) { number = tile[my][mx]; if (number == 1) { if (player->x() <= mx * 32 + 32) { xvelocity = 0; } else if (player->y() + player->height() >= my * 32) { yvelocity = 0; } else if (player->x() + player->width() >= mx * 32) { xvelocity = 0; } else if (player->y() <= my * 32 + 32) { yvelocity = 0; } } }