I'm making a game where four players are on screen at once, the camera is working fine but how do I make it so that a player can't leave the others behind?
If your camera is at the midpoint of all four character coordinates, you only need to make sure characters can't move outside (camera ordinate) +/- (screen width or height)/2 on whatever axis.
Something like this:
X("Player 1") > (xcamera - Screen Width/2)
---Player 1: Set X to (xcamera + Screen Width/2)
X("Player 1") < (xcamera - Screen Width/2)
---Player 1: Set X to (xcamera - Screen Width/2)
Y("Player 1") > (ycamera - Screen Height/2)
---Player 1: Set X to (ycamera + Screen Height/2)
Y("Player 1") < (ycamera - Screen Height/2)
---Player 1: Set X to (ycamera - Screen Height/2)