Teleporter Problems

I am having some pretty bad problems with my teleporter, I have used collidors and have tried different types of scripts. I have used this simple one:-

var destination : Transform;

function OnTriggerEnter(other : Collider) {
    if (other.tag == "Player") {
        other.transform.position = destination.position;
    }
}

so that when I go towards the collider it teleports me to the other one, however I want a two way effect, I have search and found this script:-

using UnityEngine;
using System.Collections;

public class SimpleTeleporter  : MonoBehaviour {
    public SimpleTeleporter destination;
    private Transform justJumpedSubject;

    void JumpToMe(Transform subject) {
        // we get the subject to my platform
        // and prevent it from immediately rejumping
        subject.transform.position = transform.position;
        justJumpedSubject = subject;
    }

    void OnTriggerEnter(Collider other) {
        if (other.transform != justJumpedSubject) {
                // tell the other side to receive subject
                destination.JumpToMe(other.transform);
        }
    }

    void OnTriggerExit(Collider other) {
        if (other.transform == justJumpedSubject) {
                // stepped off, don't protect subject anymore against
                // accidentally teleports
                justJumpedSubject = null;
        }
    }
}

Now the problem is, it does transport me back and fourth, but it is very temperamental, either it doesnt transport me directly onto the other teleporter, or it teleports me into a wall, or even worse it flips out and flickers. I have tried different shapes for the collider and just doesnt work.

At the moment it kind of works, but id like it to teleport me on the teleporter not near it, does this make sense? The torus' animate up and down I wouldnt think they are the problem, and I have used other scripts from the other unity answer questions, so I dont get it, heres the teleporter.

link text

I just finished developing a pretty simple script, much like your first try. If you want to teleport to the center of the target platform, you need to find the position and then subtract half the width of the target platform from your X and Z coordinates, I think.

As far as making the teleport trigger both ways... perhaps set a flag so that if I teleport from A to B, then B is disabled until I exit its trigger zone. Once I've exited the trigger zone, it becomes active again and then if I re-enter B, it teleports to A.

Make sense? Hope that helps.

Here's some code I wrote that appears to work for two-way teleport:

var target : Transform;
var isActive : boolean = true;

function OnTriggerEnter(other : Collider){
    // Check to see if this is an active teleporter
    if(isActive == true){
        // Tell the other teleporter to become inactive
        target.SendMessage("SetActive", false);
        // Teleporter collider
        other.transform.position = target.transform.position;
    }
}

function OnTriggerExit(){   
    // Check to see if this is disabled
    if(isActive == false){ 
        // If it is, set it to true.  Teleporter now active!
        SetActive(true);    
    }
}

// Helper functions
function SetActive(activeBool : boolean){
    isActive = activeBool;  
}

function GetActive(){
    return isActive;    
}

Make sure both teleporters have IsTrigger set to true, then apply this script to both teleporters. It will disable the target until you exit the trigger zone. Also, I've found that it helps to make the trigger zone taller than the platform itself, to guarantee a trigger.

Following is how I did my teleport, with some neat effects. Not sure if it's the optimum way, but works on iPhone just fine.

All you need is add it to any object with a trigger and set all teleportable objects in the layer "Object".

using UnityEngine;
using System.Collections;

public class Teleport : MonoBehaviour {
    public float teleportDelay = 0.1F; // how long before being able to teleport again
    public Transform target; // any object as to where it will be teleported

    public float speed = 1f; // how fast it is dragged in for the animated effect
    public float time = 1f; // how long does it take each of the two animation effects

    private float lastTime;

    void OnTriggerStay (Collider hit) {
        if (hit.rigidbody) {
            Teleport teleport = hit.gameObject.GetComponent("Teleport") as Teleport;
            if (!teleport) teleport = hit.gameObject.AddComponent("Teleport") as Teleport;

            if (LayerMask.LayerToName(hit.gameObject.layer) == "Objects")
                teleport.lastTime = Time.time;
        }
    }

    void OnTriggerEnter (Collider hit) {
        if (target)
        if (hit.rigidbody) {
            Teleport teleport = hit.gameObject.GetComponent("Teleport") as Teleport;
            if (!teleport) teleport = hit.gameObject.AddComponent("Teleport") as Teleport;

            if (LayerMask.LayerToName(hit.gameObject.layer) == "Objects")
            if (teleport.lastTime + teleportDelay < Time.time) {
                teleport.lastTime = Time.time;

                StartCoroutine(DoTeleport(hit));
            }
        }
    }

    public IEnumerator DoTeleport (Collider hit) {
        // animation sucking the object in
        Vector3 start = hit.transform.position;
        Vector3 end = transform.position;
        float t = 0f;
        float rate = 1f / (Vector3.Distance(start, end) * speed * time);
        while (t < time) {
            t += Time.deltaTime * rate;
            hit.transform.position = Vector3.Lerp(start, end, Mathf.SmoothStep(0f, 1f, t / time));
            yield return null;
        }
        Color hitColor = hit.renderer.material.color;

        // animation fade out
        t = 0f;
        rate = 1f / time;
        while (t < time) {
            t += Time.deltaTime * rate;
            hit.transform.position = end;
            hit.renderer.material.color = Color.Lerp(new Color(hitColor.r, hitColor.g, hitColor.b, 1), new Color(hitColor.r, hitColor.g, hitColor.b, 0), t / time);
            yield return null;
        }

        // This is the actual teleport
        hit.transform.position = target.position;

        // animation fading in, out of the teleport
        t = 0f;
        while (t < time) {
            t += Time.deltaTime;
            hit.transform.position = target.position;
            hit.renderer.material.color = Color.Lerp(new Color(hitColor.r, hitColor.g, hitColor.b, 0), new Color(hitColor.r, hitColor.g, hitColor.b, 1), t / time);
            yield return null;
        }
    }
}