I have been making a 2D multiplayer game, within which my players handle collisions using a box collider. But with this, comes the problem of them being able to stand on top of each other. I still want my characters to be able to push one-another horizontally with these box colliders, but don’t want them to stand on top of each other. Would anyone happen to have a solution for this?
When I did 2D games in plain C/C++ with SDL, I usually had a array that held all objects, like all the players data or npcs or everything, if Player A wants to move left, it first runs threw the array, and checks if anything is already there, if so dont move, if its open then move.
like
public struct charlocs
{
int x,y;
}
public charlocs[] MyCharsLocs = new charlocks[1024];
......
.......
when Player wants to move
something like
for(int x = 0; x < 1024; x++)
{
if(myNewX == MyCharsLocs[x].x) return; // dont move something already there
}