I am working on this game about a player in a dungeon and the player needs to be able to teleport from door to door when it walks in it. The problem is is when the player enters the door it gets teleported, but when it is teleported it creeps back to its original position. I don’t know what causing it and would like it to be fixed. I thought that my player movement script was interfering with it, but I turned it off before the player would teleport and it would still do it. I don’t know if I am clear enough, but if you have any questions please ask.
Here is my script for the door:
public class DoorController : MonoBehaviour
{
public Camera CameraA;
public Camera CameraB;
public GameObject Player;
public Transform destination;
public bool DoorOnTop;
//if collider hits something
public void OnTriggerEnter2D(Collider2D collider)
{
//checks if it is player
if (collider.gameObject.tag == "Player")
{
SwitchCamera();
TpPlayer();
}
}
private void SwitchCamera()
{
CameraA.enabled = false;
CameraB.enabled = true;
}
private void TpPlayer()
{
if(DoorOnTop)
{
Player.transform.position = new Vector2(destination.position.x, destination.position.y + 1.15f);
}
if (!DoorOnTop)
{
Player.transform.position = new Vector2(destination.position.x, destination.position.y - 0.85f);
}
}
}