void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == “Teleporter”)
{
Debug.Log(“collision succsessfull”);
transform.localPosition = new Vector3(230, 60, 191);
}
}
this is my script i put it on the Fps controller from the standart assets.
the GO i use as my teleporter has the tag Teleporter.
the strange thing is the player moves to the dedicated position for about a frame and then hes back where he started, but it seems the if condition isnt even met because i dont get the debug message in the console.
I suppose the script you wrote is attached to player, so…
I suggest you to add a cooldown (code below hasn’t been tested):
bool CanTeleport = true;
void OnCollisionEnter(Collision col)
{
if(col.gameObject.CompareTag("Teleporter") && CanTeleport)
{
CanTeleport = false;
StartCoroutine(Tele(3, Vector3(230, 60, 191)));// Cooldown time and coordinates to teleport
}
}
IEnumerator Tele(int CooldownTime, Vector3 Coordinates)
{
Debug.Log("Teleporting...");
transform.localPosition = Coordinates;
//Seconds to allow the player to be teleported again
yield return new WaitForSeconds(CooldownTime);
CanTeleport = true; //delete this if u want your player stop teleporting permanently
}
hmm its still the same as before and there is no debug.Log with this code either