How can I program a 'wrap-screen'?

In Asteriods, if you fall off one side, you'll appear on the other directly reversed from your position. How can I program such a thing?

Would it be as simple as doing a raycast backwards until it hits a collider I would place at the boundries of the camera viewport, and then putting the ship at that point?

Thanks, Elliot B.


Top.js

var bottom : GameObject;

function OnTriggerEnter (other : Collider) {
    other.gameObject.transform.position.x = bottom.transform.position.x;
}

I'm a noob in unity, but have done some programming...

Excuse the simplicity of the suggestion (perhaps you are asking a far deeper question than I am perceiving).

What I have done in the past is simply detect the object passing a boundary. You could probably do it with a simple colision trigger, and simply "warp" the object to the opposite side of the screen by changing its location. It should still retain its motion.

Hope this is not syntactically bogus, but you get the idea:

transform.position.x = -512

Example: when the "ship" is leaving the right side of the play area, at the moment it is still half visible, simply reset the X position to the left side of the screen.

The down side to this is you can't see the object leaving on one side and emerging from the other at the same time... but it's not a serious flaw in my experience.

Of course for many objects, like in asteroids, you would probably have the boundary object detect what object triggered it, and then change the position of the object that touched it... this would work for the asteroids as well as the ship. Even "shots" would warp properly if that is what you wanted.

Ryder

Where would you put ("collision detected")? And will it work for 3D?