Code is acting different depending on call

Here are the simple code bits:

void Update() {
    if(isTeleporting) {
        teleport(new Vector3(transform.position.x, transform.position.y, transform.position.z - 1));
    }

    if (Input.GetKey(KeyCode.F)) {
        teleport(new Vector3(transform.position.x, transform.position.y, transform.position.z - 1));
    }
}

Every frame this checks if an ‘isTeleporting’ variable is true, if it is, it will call the teleport method. It also checks if I hit the ‘F’ key, if I do, it does the exact same code.

Teleport method:

public void teleport(Vector3 pos) {
    isTeleporting = false;
    Debug.Log("Teleport!");
    transform.position = new Vector3(pos.x, pos.y, pos.z);
}

Pretty simple, it sets the ‘isTeleporting’ back to false so it doesn’t teleport every frame, prints a debug, and finally actually moves the object.

So, how does ‘isTeleporting’ become true? If I come in contact with a trigger.

public GameObject[] startLocs;
public bool isTeleporting = false;

void OnTriggerEnter(Collider col) {
    for (int i = 0; i < startLocs.Length; i++) {
        if (col.gameObject == startLocs*) {*

Debug.Log("Player entered: " + col.gameObject.tag + " " + i);
isTeleporting = true;
}
}
}
If the player triggers a startLocs trigger, then it will proceed to set isTeleporting to true.
Basically, all this is me trying to set up a door system. I’ve tried a million different ways but for some reason the player is not moving. The debug positions say the positions are changing, but he is in the same place.
The problem with this code is, when I come in contact with a door with a trigger, it calls the teleport method (because ‘isTeleport’ is set to true) and prints the debug “Teleport!” statement, but player does not move. Yet, when I hit the ‘F’ key, it again prints the debug “Teleport!” statement, except this time, the player does move. Why does this happen? And how can I fix this?
Any help is appreciated.

I couldn’t respond to your last comment below the main question, so I will put this here. It might be best to stop player movement when you enter a teleport trigger. That way, you can just do the instantaneous teleport and not worry about all the sliding about through other triggers.

These scripts might work for you with a little bit of modification. Basically, the teleport trigger objects each need to have a script that has a vector 3 destination variable. The player has a playercontrol script for movement and a teleport script for teleporting. When the player enters a teleport trigger(tagged with “TeleportTrigger”), movement is stopped with a call to StopMoving() on the PlayerControl script, then the player is teleported to whatever the destination is that is contained in trigger object’s TeleportTrigger script. This uses a coroutine for movement and “MoveTowards” instead of lerp. Hope it helps.

For Movement (attached to the player):

using UnityEngine;
using System.Collections;

public class PlayerControl : MonoBehaviour
{
    public float speed = 5.0f;
    public bool isMoving = false;

    void Update()
    {
        if ((Input.GetKey("w") || Input.GetKey(KeyCode.UpArrow)))
        {
            StartMoving(Vector3.forward, 1);
        }

        if ((Input.GetKey("s") || Input.GetKey(KeyCode.DownArrow)))
        {
            StartMoving(Vector3.back, 1);
        }

        if ((Input.GetKey("a") || Input.GetKey(KeyCode.LeftArrow)))
        {
            StartMoving(Vector3.left, 1);
        }

        if ((Input.GetKey("d") || Input.GetKey(KeyCode.RightArrow)))
        {
            StartMoving(Vector3.right, 1);
        }
    }

    void StartMoving(Vector3 direction, float distance)
    {
        if (!isMoving)
        {
            isMoving = true;       
            StartCoroutine(Move(transform.position + (direction * distance)));
        }
    }

    public void StopMoving()
    {
        isMoving = false;
        StopAllCoroutines();
    }

    IEnumerator Move(Vector3 targetPosition)
    {
        float step = speed * Time.deltaTime;
        while (isMoving && (transform.position != targetPosition))
        {
            transform.position = Vector3.MoveTowards(transform.position, targetPosition, step);
            yield return null;
        }
        isMoving = false;
    }
}

For Teleportation (attached to the player):

using UnityEngine;

public class TeleportControl : MonoBehaviour
{
    void Teleport(Vector3 destination)
    {
        transform.position = destination;
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("TeleportTrigger"))
        {
            GetComponent<PlayerControl>().StopMoving();
            Teleport(other.GetComponent<TeleportTrigger>().teleportDestination);
        }
    }
}

Teleport Destination (attached to teleport trigger object):

using UnityEngine;

public class TeleportTrigger : MonoBehaviour 
{   
    //set this in the inspector for each trigger object
    public Vector3 teleportDestination;
}

I’m afraid I haven’t got an answer for you but I do have a comment that may or may not fix the issue - instead of playing around with this public bool, why not just call the teleport function straight off when the collision is detected?

 public GameObject[] startLocs;
 public bool isTeleporting = false;
 void OnTriggerEnter(Collider col) {
     for (int i = 0; i < startLocs.Length; i++) {
         if (col.gameObject == startLocs*) {*

Debug.Log("Player entered: " + col.gameObject.tag + " " + i);
// Set up a reference to the object where the teleport function is attached and call that function here
}
}
}
Then you can just keep the ‘if F key is pushed down’ one as is, since this works already, in the update function.