Transform position?

Hello. I want to make a space shooter like asteroids (where the screen wraps around, so if the player hits an edge, they will go to another place). When I am using transform.position, how can I use the player's current position for two values and have the other one be incorporated into a simple math function? So it would be something like this

transform.position = Vector3(Current X, Current Y, Current Z-30);

Thanks.

I would do a check for objects where I use the "size of the screen" as margins. These can be found at application start.

Look here: http://unity3d.com/support/documentation/ScriptReference/Screen.html

Now you have the MAX pos for both directions. Then make a simple check on the coords of each object. Are we outside? if we are, then add/subtract the size from the objects pos.

Depending on your "center" position of your camera, you might have to ajust the values a bit, but I expect you to place 0,0,0 in center of screen for this example.

So I globally initiate the width and height and divide by 2 so I have the center position.

void function CheckBorder(Transform o)
{
    if (o.position.x < xHalfScreenSize) { o.position.x += xScreenSize }
    else  // else is important, otherwise you would switch back and forth in same check
    {
       if (o.position.x > xHalfScreenSize) { o.position.x -= xScreenSize }
    }

    if (o.position.y < yHalfScreenSize) { o.position.y += yScreenSize }
    else  // else is important, otherwise you would switch back and forth in same check
    {
       if (o.position.y > yHalfScreenSize) { o.position.y -= yScreenSize }
    }
}

Now you should be able to throw any object into this function.

As you might see, this makes the object "swap" inside visible area, thats not good. So add a little "extra" border to the screen sizes. A good value must be at least the max size of your object. Lets say your largest meteor would be 256 pixels, then just add 256 to the screen sizes, before dividing.

hope this helps.

You could also check for collision like so:

var changePosition = false;

function OnControllerColliderHit (hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "Typewhateveryouwant") // Make sure the object you collide with has the same tag as written.
{   
changePosition = true;
}
}
function LateUpdate ()
{
if(changePosition) = true
{
 transform.position = Vector3(?,?,?) // Write the position you wanna "respawn" to.
}
}

Hope that helpes :)