The best I can come up with is to manually copy the level onto the edges of the level and when a player crosses that border put them at the other edge. However this would cause issues with items being moved near the edges and potentially other players and AI characters.
Obviously both of those solutions suffer from the same problem â theyâre just faking it, so objects crossing the seams arenât actually there.
Now If you truly want to have a game world that loops seamlessly â itâs time to make the game 3D (yes, really).
You will need to constrain your 2D game to either a 3D Cylinder or 3D Torus â depending on your needs, of course. Each of these shapes will provide you with the world-wrapping you desire; with a Cylinder providing 1 axis of wrapping, and a Torus providing 2 axes of wrapping.
After you have recreated your game to play on the surface of the 3D shape â the rest is just a rendering battle, of which is significantly easier to solve than attempting to brute-force wrap a 2D coordinate system and getting everything to work properly (like physics queries?).
Now I have no idea how to make the shader necessary to âunwrapâ the world to make the game appear 2D again. But I know its possible â because Curved World is doing something very similar to what you need (and in some cases may be a solution to the rendering part of this problem).
All I can say is, best of luck!
This is not an easy problem to solve and it may be worth asking yourself if this is the hill you wish to die on.
It may be worth changing your gameâs design so you can just fake it.
@NotaNaN Thanks! That was pretty easy to implement, didnât went the shader route though but rather the âdynamic teleportingâ as your link calls it. Works pretty great except for moving over the seam with particle systems, if I somehow could get them to be deterministic that would solve that issue.
For anyone interested, the simple and short explanation is to copy everything on the playfield and paste it left and right of the playfield. (and up and down and all 4 diagonals if youâd want 2D scrolling instead of 1D) this is good enough for all static items like level geometry and such things.
Destroyable objects youâd need to have the copies only listen to the copy on the playfield, same with active elements (like bullets or buttons).
Physics object are a bit more tricky, but youâd need to force set the rotation and position of the copy to that on the playfield. If you somehow need to interact with object âpast the seamâ (like a trigger attached to the player character) youâd dynamically change the copy with the original outside the playfield.
And with things like distance joints you should let the item be able to move past the seam until both the distance joint object and the object itâs attached to is past the seam and further do the same check if the object is a copy or not (and if thatâs the case replace that with the original). I can still see this getting to be an issue with multiple players or multiple objects trying to interact with it at the same time, but for my own game itâs a non-issue.
Right now, my only issue is the whole particle system near/on the seam.