Wrap-Around Level - Advice on Best Method

Ok, I’m working on a 2d side-scroller. I’d like the level to wrap at the ends so it’s an infinite loop. It would be similar to asteroids wrap-style except the player would stay centered in the screen as they move and the level would wrap outside the camera bounds. Think Flinstones-style background looping.

I can think of three methods, but not sure which, if any, would work well in Unity. I’m a little new to it.

  1. Write it like a 2D Tile-based game. Send everything from one edge to the other when it hits the bounds. Player moves, other objects are fixed.

  2. Fix the player, but move the platforms and enemies towards or away from the player to simulate movement. Wrapping would happen by ‘teleporting’ objects at the bounds, outside the camera.

  3. Place the level inside or outside a column. Tie the character to the column and follow with the camera. Find an art solution to diminish the cylinder effect.

Any advice or alternative solution is appreciated.

You could use two cameras when the player gets to the edge of the level. One camera would cover the side the player is on and the other would cover the side the player is moving to. Alter the each camera’s viewport rect to match how close the character is to the edge. ie if the edge of the last tile on one side is at viewportpoint.x = 3/4th, then that cameara’s width should be 3/4th and the other camera’s width should be 1/4th.

Of the top of my head, I don’t know exactly what the best method of sizing the cameras is.

Heh, I’ve always found it pretty easy to just have a box trigger on either side that teleports the player to the other side.

It’s not that hard to do any of the ones you mentioned, really. It’d be funny to have the bullets wrapping around a cylinder…

Could you duplicate your 1st screen to the end, then once the last screen (looks same as 1st) has been fully shown, move the camera to the 1st screen? Should appear seamless, and easy to do. You would have to move / duplicate any objects between the two screens and maintain their state.

Have you considered a random level that goes for infinity? Destroy previous objects and dynamically create future ones. This could be used for non-random worlds too if you can define your level, as you suggested, as tile based. You can do non-tile too if you store each object’s parameters (size, position, texture, etc) in an array and dynamically create them. Just some thots.