Search Unity

2D Wraparound like 'Asteroids' but with a twist!: Camera attached to player

Discussion in '2D' started by SummerFun, Jun 22, 2017.

  1. SummerFun

    SummerFun

    Joined:
    Dec 25, 2015
    Posts:
    5
    Is there any way to seamlessly have wraparound but with the camera following the player?

    In the asteroids example, the only difference is that the camera is always following the player. When the player moves too far off screen that there is a 'boundary', that boundary should be filled with the space that the player will come back to on the other side of the screen. It should look connected and is almost like visualizing portals. I'm trying to achieve this so that if a spaceship reaches an outer edge of the galaxy it will just loop back around but without any 'teleportation' feel. It'll just loop around like a galaxy would and continue on its merry way on the opposite side of the unity spectrum.
     
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    You should be able to achieve this with cloning techniques (this is how Portal works if I remember correctly), or even just simple camera tricks depending on the complexity of the scene(s).

    Maybe you could set up your game like regular Asteroids, where objects wrap to the other side of the field when they go out of bounds, but then set the camera that views the play area to render to a texture.

    This texture is applied to a set of 9 quads that are all the same size as the play area, and the camera that renders to the screen is actually looking at these quads. When the cam moves across a boundary, you could move the farthest quads over to the other side so that the screen cam is always centered on the center one and won't reach any unhandled edges.

    I got in touch with my artistic side to draw this:

    upload_2017-6-22_12-13-1.png

    There may be considerable overhead with this method depending on the target platform, but it might be mitigated by deactivating or removing quads that are not in view.

    I'm certain there's a more elegant way to to this, but this is an option.
     
    SummerFun and LiterallyJeff like this.