5
\$\begingroup\$

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: enter image description here 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?

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – wolfdawn Nov 1 '14 at 11:52
  • \$\begingroup\$ Are you using a standard engine/framework? \$\endgroup\$ – Kelly Thomas Nov 1 '14 at 13:50
  • 2
    \$\begingroup\$ You're after screen wrapping... gamedevelopment.tutsplus.com/articles/… scroll down to advanced wrapping for the tutorial on what you want \$\endgroup\$ – Savlon Nov 2 '14 at 4:41
  • \$\begingroup\$ 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! \$\endgroup\$ – Dev7x Nov 4 '14 at 5:28
1
\$\begingroup\$

My solution would me to create 2 identical objects that are spaced apart by the width of the screen.So when the first object is in the middle of the view (for example left one), the other object would be screen width apart from the first object i.e. off the view. When you move the first object the second one moves along with that object, keeping the space between them the same. So when hte first object disappears from the view second object will appear.Just a suggestion :)

\$\endgroup\$
  • \$\begingroup\$ This is not a bad suggestion, albeit one frought with implications. What happens if both sides detect collision (eg. player dies) -- do you lose two lives? Do you get power-ups twice? \$\endgroup\$ – ashes999 Feb 20 '17 at 18:11
0
\$\begingroup\$

If your room take up the whole game screen (a bit like your image), there not much you can do, because you do need to have part of that orange circle both on the left and on the right of the screen.

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.