- Home /
Infinite Teleport Loop... need to "throw" player out of teleport.
Hey all,
I've set up a simple teleport script... which is working just great, save for one thing. The player is getting stuck in an infinite loop between the two teleports. To fight this, I would like to slightly throw the player out of the destination teleport. Which commands do I need to utilize? Thanks in advance, here's my code so far:
//Defining Variables var destination : Transform; var TeleportAudio: AudioClip;
//Player Enters Trigger function OnTriggerEnter(other : Collider) {
//Play Teleport Audio if (TeleportAudio) AudioSource.PlayClipAtPoint(TeleportAudio, transform.position); if (other.tag == "Player") { //Transport Player to Pre Defined Destination var startPosition = other.transform.position; other.transform.position = destination.position; var moveDelta = other.transform.position - startPosition; //Move camera with player so it doesnt go wildly through the air
Camera.main.transform.position += moveDelta;
}
}
Answer by DaveA · Apr 11, 2011 at 08:03 PM
I've always used separate 'enter teleport' and 'exit teleport' markers, so you set the player at the 'exit' specifically. But you could just add the player's 'forward' direction (perhaps times some distance' to the destination, so it kicks them just past it.
Hmmm.. thats not a bad plan actually. I'm fairly new to code, exactly how and were would I augment the players distance to the destination? Thanks!
Your answer
Follow this Question
Related Questions
How to alternate two VideoPlayer objects to loop a video 1 Answer
Teleport 2D Player to another room 2 Answers
Skyrim style door teleport 0 Answers
Cannot use triggers to teleport an object? 1 Answer
How do I make an object teleport 2 Answers