Looping 2D level

How can I make a looping 2D level?

Similar to this:

Essentially the gameworld being a cilinder.

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.

+1

1 Like

It seems that shaders or some form of camera stacking is your best bet (unity - Seamless 2D wrap-around effect - Game Development Stack Exchange).

Obviously both of those solutions suffer from the same problem — they’re just faking it, so objects crossing the seams aren’t actually there. :frowning:

Now If you truly want to have a game world that loops seamlessly — it’s time to make the game 3D (yes, really). :sunglasses:

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. :smile:

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?). :eyes:

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). :face_with_spiral_eyes:

All I can say is, best of luck! :slight_smile:
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.

its too complicated there should be a better way, its a nightmare to setup the physics for this

@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.

1 Like