- Home /
Teleport problem
{
public GameObject objToTP;
public GameObject tpLoc;
void OnTriggerEnter(Collider other)
{
if ((other.gameObject.tag == "Player"))
{
objToTP.transform.position = tpLoc.transform.position;
Debug.Log ("Teleported");
}
}
void OnTriggerExit()
{
print ("Teleport.Success");
}
}
I am trying to teleport my FPS controller by adding this script to the teleport trigger. I also added an empty as the tpLoc and the FPS controller to the objToTP. It is giving me the "Teleported" and "Teleport.Success" in the console but the fps controller is not being teleported. I think that I should mention that I have the same code just with a UI and having to press E. That one works. I also have this one in a different scene.
Answer by tanoshimi · Mar 19, 2017 at 12:19 PM
That rather suggests that you haven't assigned the correcy object to the objToTP variable. However, you really don't need it anyway - if it's the player that enters the trigger and the player that you want to teleport, you can change your code to:
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
other.transform.position = tpLoc.transform.position;
Debug.Log ("Teleported");
}
}
Answer by Gohst002 · Mar 22, 2017 at 10:55 AM
Thanks a lot but I found out that I applied the script to the wrong scene. :D
Your answer
Follow this Question
Related Questions
How To Trigger Animation When Bullet Hits With UFPS 0 Answers
Hi, I need some help to understand things about Multi First Person Controller in the same scene. 1 Answer
How do I prevent my fps player from flying? 1 Answer
How do I convert my FPS controller movement script to a rigidbody to prevent clipping. 0 Answers