How to generate a “loop room” in a platformer game (by Unity)?

I want to build a level with a room whose left edge is linked to right edge in a 2D platformer game in Unity.

My goal is let all objects disappear in one side will appear in other side of the room. Just like this: Both sides should have collision with other objects.

Right now I'm doing this by cloning objects on the other side, but it is too complicated. Is there any other good way to solve this?

• see this This is available in Nape out of the box. Please tag your question as Unity if you are only interested in that. You need a Portal behavior which basically means an object is partially in two places at once and checks collisions against multiple objects in multiple places. – wolfdawn Nov 1 '14 at 11:52
• Are you using a standard engine/framework? – Kelly Thomas Nov 1 '14 at 13:50
• You're after screen wrapping... gamedevelopment.tutsplus.com/articles/… scroll down to advanced wrapping for the tutorial on what you want – Savlon Nov 2 '14 at 4:41
• Hi guys, thank you for your answers. Currently I'm using Unity and I will tag this question. And thank you for Portal and Screen Wrapping solution, they are really helpful! – Dev7x Nov 4 '14 at 5:28

If your world is large and you platformer center its view on the character, there's more hope. Let's say your world has a width of h. For example, split your world in two parts, at about the x-distance h/2. Whenever the character is in the left part, leave the object overlapping the vertical side with coordinates at about 0. Whenever he is in the right part, add h to their x-position.
Of course this creates a lot of computation if the character crosses the side a lot, so it's improvable. For example you could split down even further, and have the changes made only when the character crosses the x-position of -h/4 to teleport him/her at 3*h/4 and when he/she crosses 5*h/4 to teleport him/her at h/4.