0

I am trying to get my player to teleport to a point in the mesh from a trigger that is activated in another mesh, more specifically in a ceiling. I tried this but it leaves me the player in a corner of the mesh where he is already.

void OnTriggerEnter(Collider other)
{
    if (other.gameObject.CompareTag("Player"))

    {
        _playerPrefab.transform.position = _initialposition.transform.position;
    }
}
olivia
  • 13
  • 4
  • Where is _playerPrefab defined? What is _initialPosition? There's a few confusing things here with your naming convention. You should never be moving a prefab (a prefab is a "template" and not a living Game Object). I also find it strange that you _initialPosition isn't already a Vector (hence "position"). – Erik Overflow Mar 10 '20 at 14:18
  • `[SerializeField] private GameObject _playerPrefab;` – olivia Mar 10 '20 at 14:26
  • _ initial position is where I want to go, it is a transform. Sorry, the player is in the game – olivia Mar 10 '20 at 14:27
  • have a search you can link meshes together , you wouldnt need to move it specifically you would use a mesh link – BugFinder Mar 10 '20 at 14:32
  • How would that be? Can you show me? – olivia Mar 10 '20 at 14:35

3 Answers3

0

Try using the warp function that the NavMesh agent provides :

_playerPrefab.GetComponent<NavMeshAgent>().Warp(_initialposition.transform.position)
David Buck
  • 3,752
  • 35
  • 31
  • 35
0

If you want to use the NavMesh API, your player needs to have a NavMeshAgent.

Then you can simply call yourAgent.SetDestination(yourDestination)

Jichael
  • 820
  • 6
  • 17
0

In the end I was able to solve it by changing the position with tranform.position, disabling the navMesh Agent and setting the speed to zero.

olivia
  • 13
  • 4