Realize toroidal movement

Hi guys!
I’ve some doubt on how to realize a toroidal movement. Beneath you can find an image that explain what I mean for “toroidal movement” (remember the old snake on the nokia 3310?).

I want my game object to gradually disappear when it goes on the border of the screen and appear gradually on the opposite. Looking to the image I guess is more clear:

alt text

Let’s suppose that the arrow is my game object and the grey part the iPhone Screen.

Thanks in advance to all of you that will be of help!

S.

Simple- have a second ‘body double’ object which moves in on the other side of the screen in perfect sync! Just keep a second object slaved to the first one, set up so that it would come onto the screen as soon as the ‘real’ one disappeared. Then, when one is totally off, delete the unneeded one and make the new one the ‘real’ one.

You’d need one set of body doubles for each dimension, assuming this works at the top as well. In fact, if you made every second body double mirror inverted, it’d be like a klein bottle instead!

At the end I solved it in another way.
I made 4 invisible wall as a container of the scene and create a script for each wall that make every wall triggered and take decision with reference of the function OnTriggerStay(). When the center of mass of the gameobject exceed the position of the wall the gameobject is teleported. This means that its coordinates are changed of a certain factor that is the height and/or the width of the screen.

Below the code I used on a wall:

public class NorthWallTeleportation : MonoBehaviour {
	
	void Start(){
		this.collider.isTrigger = true;
	}
	
	void OnTriggerEnter (Collider collider){
	}
	
	void OnTriggerStay(Collider collider){
		if(collider.gameObject.tag == "TagOfTheObjectYouWantToTeleport" && collider.gameObject.transform.position.x < this.transform.position.x){
			collider.gameObject.transform.position = new Vector3(collider.gameObject.transform.position.x+2.9f,collider.gameObject.transform.position.y,collider.gameObject.transform.position.z);
		}
	}
	
}

The 2.9f factor that I used here is the width of my screen and the fact that I add this factor to the x coordinate depends on the scene orientation.

Hope this is usefull.

Best,

S.