- Home /
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:
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.
Answer by syclamoth · Dec 07, 2011 at 06:49 PM
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!
Thanks for the quick answer! I think it's a good idea, I'll try to implement that feature tomorrow ;)
Answer by Shooter · Dec 12, 2011 at 12:03 PM
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.
Your answer
Follow this Question
Related Questions
Window flicker when moving camera 2 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Making a bubble level (not a game but work tool) 1 Answer
Make enemy appear in front of player and then disappear at random times 2 Answers
How do you find an object in the middle of the screen? 1 Answer