Door Script doesn't change player position?

I have this building in my game where I want to be accessed through this door. So when you are close enough to the door it teleports you to the other side. Although for me this doesn’t work. It doesn’t teleport the player anywhere. Except if I change the “if distance <= minDist” to “if distance >= minDist”. My player uses Character Controller. Help would be appreciated. :slight_smile:

Here’s my code?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;



public class Door : MonoBehaviour
{
    public Transform other;
    float minDist = 5;
    public Transform teleport;
    public GameObject player;
    public float distance;



    void Start()
    {

    }

    void Update()
    {
        if (other)
        {
            distance = Vector3.Distance(transform.position, other.transform.position);
            if (Input.GetKeyDown(KeyCode.E))
            {
                if (distance < minDist)
                {
                    player.transform.position = teleport.transform.position;
                }
            }
        }
    }

}

First you should say what debugging you’ve done. I mean you’re asking here but debugging obviously involves narrowing it down to which part isn’t doing what you expect. In your case, is the distance correct? Is the key-down being registered? Is the distance < minDistance correct? What is minDistance showing in the inspector (it might not be 5), does player.transform.position = XXX do what you expect if you just do it ignoring the rest of the logic.

This is what you should check before asking which is why I’m asking about what you’ve done first.