Search Unity

Moving player across bounds

Discussion in 'Scripting' started by Disaster, Sep 19, 2011.

  1. Disaster

    Disaster

    Joined:
    Oct 31, 2009
    Posts:
    43
    This is hard to describe, but I'll do my best. I'm trying to figure out if it would be possible create Asteroids style level bounds. For example, if the player was to leave the screen bounds on the left, they would start to appear on the right, as if the level wrapped round. I have tried to illustrate what I mean:



    In 1, the player is moving left, in 2. he starts to leave the screen but appear from the same position at the right hand side.

    Does anyone what this technique is called and how I might achieve this effect in Unity?
     
  2. justinlloyd

    justinlloyd

    Joined:
    Aug 5, 2010
    Posts:
    1,680
    What you are attempting to do is emulate a computer memory artifact, the equivalent of showing static and snow on a LCD screen to simulate an off-station television.

    You can do the wrap-around effect a number of different ways: 1. Render to texture. 2. Use a custom full-screen shader. 3. Use a dual camera setup. 4. Create a proxy object. 5. Render the object twice (or three or four times) when the object approaches a boundary. If you are not familiar with writing a custom shader, I would say option 1 is your simplest.
     
  3. novashot

    novashot

    Joined:
    Dec 12, 2009
    Posts:
    373
    I would just have the object check it's x position..... If it's above screen width(right side of screen) + a bit.... Set it's x position to 0 (left side) - a bit. Check for x position < 0 for the opposite way.


    If you don't want to continuously check player position, have a trigger off screen; when player hits it... Record his position and modify his x pos depending on what side of the screen he exited.

    Maybe I misread the situation, but that's what I'd do for wrapping the screen.
     
  4. justinlloyd

    justinlloyd

    Joined:
    Aug 5, 2010
    Posts:
    1,680
    He wants the image to wrap around too, not just the conceptual point position of the object.
     
  5. Disaster

    Disaster

    Joined:
    Oct 31, 2009
    Posts:
    43
    Yea repositioning the player isn't so hard, it's just that "wrap around" effect I am having trouble with.

    I don't really want to use a render to texture, it seems a bit of a messy way of doing it, not to mention it requires Pro. I'm thinking the only real solution without writing crazy shaders (which is a bit beyond me) is to go down the proxy object route and see if I can get that to work.

    Is there a particular name for this technique? Google isn't turning up much.
     
  6. justinlloyd

    justinlloyd

    Joined:
    Aug 5, 2010
    Posts:
    1,680