- Home /
How to implement teleportation w/o collisions
Hi everyone,
I'm working on a game that implements seamlessly teleporting between two worlds. I'm new to Unity, and my first instinct was to make two terrains of identical size, parallel to each other, and 1000 Y units apart from each other. Then I created this script for Javascript to apply to the standard FPS module:
var universe = false;
function Update () {
if(Input.GetKeyDown("x") && universe == false) {
Camera.main.transform.position.y += 1000.0;
universe = true;
}
else if(Input.GetKeyDown("x") && universe == true) {
Camera.main.transform.position.y -= 1000.0;
universe = false;
}
}
Which works fine. When I press "X", the camera essentially switches worlds, to the exact same X and Z coordinates, and translate 1000 Y units. My question is how to check if the place I'm teleporting to has an impassable object like a mountain or something there already, and to forbid teleporting to those places.
If anyone has a better idea of how to implement teleportation, feel free to share!
Thank you for your help in advance!
Answer by DaveA · Feb 28, 2013 at 09:15 PM
You might do a raycast from high above the destination point, straight down, and set the player to the x,z of teleport, and y of ray hit.
The teleports I've always seen have specific entry/exit points, so this does present an interesting twist.
We implemented this and it works pretty well. Only thing is that for steeper slopes, we sometimes fall through the terrain. Not sure if you would have any suggestions about that
Your answer
Follow this Question
Related Questions
OnCollisionEnter not working 1 Answer
two objects colliding 3 Answers
Collide detection with tag [JS] 0 Answers
Car dynamics? 0 Answers
2D Collision 1 Answer