- Home /
teleport destination differs when player hits trigger from different positions
I simply want my player to teleport from one position to another when it hits the trigger. It seems to work fine, except for one problem. The destination point changes when the player hits the trigger from different positions. For example: When the player hits the 2d box collider on top, the player is teleportet under the destination point I set. If the player hits the 2d box collider on the bottom, the player is teleportet correct. I tried to change form/size of the collieder, but nothing solved the problem. Here the Script I'm using:
using UnityEngine;
using System.Collections;
public class Warping : MonoBehaviour
{
public Transform warpTarget;
IEnumerator OnTriggerEnter2D(Collider2D other)
{
ScreenFader sf = GameObject.FindGameObjectWithTag ("Fader").GetComponent<ScreenFader> ();
GameObject
Player = GameObject.Find ("Player");
moveplayer
moveplayer = Player.GetComponent<moveplayer> ();
moveplayer.canMove = false;
yield return StartCoroutine (sf.FadeToBlack());
other.gameObject.transform.position = warpTarget.position;
Camera.main.transform.position = warpTarget.position;
yield return StartCoroutine (sf.FadeToClear ());
moveplayer.canMove = true;
}
}
Have you tried using Debug.Log to print the positions? Also, you are setting the Cameras position to the warp targets position. Not sure if that's intended but you may have an issue with the view as its on the same position as what you're trying to view.
Your answer
Follow this Question
Related Questions
Player does not teleport to the right location 0 Answers
my OnTriggerEnter function won't get called 1 Answer
Help Cannot convert type 'PhotonPlayer' to 'UnityEngine.GameObject' 1 Answer
Issue with Teleporting Object 1 Answer
teleport an object three quarters of its distance with the player after a certain time 2 Answers