- Home /
Teleport on trigger enter
Hi, I am working on some mobile app & in that i want the player to reach its starting location after entering the triggered area....i have used the below code
var destination : Transform;
function OnTriggerEnter(other : Collider) {
if (other.tag == "Player") {
other.transform.position = destination.position;
}
}
i have even tagged the entire player relative controls game object as player & camera object under it as a childobject. But still i don't know why the camera & the sphere collider is going away from the sphere object(player). Pls help me out.
If you aren't getting the collision ever then I'd suggest reading this
@whydoidoit: I can't able to find what i am looking at in that link...
Answer by vladGold · Nov 14, 2020 at 08:32 PM
try: other.transform.position = destination.transform.position; It can work
Answer by hvilela · Oct 17, 2012 at 08:34 PM
I guess your collider is not directly associated with the player "root" game object, am I right? This code moves the game object associated with the collider, not everything that is tagged as player. Give appropriated names to all your game objects hat are child of Player and print the name of the object that you're moving and you'll understand the issue:
var destination : Transform;
function OnTriggerEnter(other : Collider) {
if (other.tag == "Player") {
Debug.Log("Moving " + other.name);
other.transform.position = destination.position;
}
}
PS: If the game object that hold the collider is child of player you can use:
other.transform.parent.position = destination.position;
Your answer
Follow this Question
Related Questions
Teleportation Loop issue 1 Answer
Teleporting projectiles, and maintaining speed 3 Answers
my OnTriggerEnter function won't get called 1 Answer
Teleport objects 0 Answers
Simple one-way teleport? 2 Answers