I’m very new to unity and I’m just trying to make a simple teleporter to move the player character from one part of the level to another. I’ve turned a cube into a trigger, placed it where I want it, and attached a script to it which should make the player’s transform.position the same as the target’s transform.position. However this is not working for some reason. Instead of teleporting, what happens is the player appears to get pulled into the trigger when they touch it.
Here’s the code for the trigger:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Teleporting : MonoBehaviour
{
public Transform teleportTarget;
public GameObject player;
private void OnTriggerEnter(Collider collider)
{
player.transform.position = teleportTarget.transform.position;
}
}
The Gameobject, player gets set to the player and the teleportTarget gets set to the empty.
Thanks in advance