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;
    }
}

1 Answer

1

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!

NM... worked flawlessly, thanks!