NavMeshAgent going to wrong destination
I have a NavMeshAgent on my enemies and they the destination is set to the players location. I have debug statements showing the player's transform and what is being set to the nav destination and they are correct but my enemy is going to 0,0,0. Here is my code. Ignore all the commented out stuff since I'm trying to troubleshoot what is going wrong.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EmenyMovement : MonoBehaviour
{
Transform player;
NavMeshAgent nav;
PlayerHealth playerHealth;
EnemyHealth enemyHealth;
public string QuestName = string.Empty;
// Start is called before the first frame update
void Start()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
Debug.Log("Player position: " + player.position);
nav = GetComponent<NavMeshAgent>();
// nav.enabled = false;
}
// Update is called once per frame
void Update()
{
nav.destination = player.transform.position;
Debug.Log(nav.destination);
/* Quest.QUESTSTATUS Status = QuestManager.GetQuestStatus(QuestName);
Debug.Log(Status);
if (Status == Quest.QUESTSTATUS.ASSIGNED)
{
Debug.Log("in quest assigned");
//nav.enabled = true;
}*/
}
}
I have to have this completed today so PLEASE HELP!
Answer by mishelbi · Apr 27, 2019 at 06:50 PM
Never mind. I figured it out! In my enemyAttack script I have > 0 on player health instead of < 0 . When < 0, I warp the enemy to a different position.
Your answer
Follow this Question
Related Questions
Script seems inactive? 2 Answers
Unity Navmesh agent patrol and chase player script issues. 0 Answers
Need help with Nav Mesh Agent getting "stuck" at high speeds 0 Answers
about race game’s skip race function. 0 Answers
ai patrol and chase question 0 Answers