- Home /
Code Causing Confusing Result
My movement code is causing my enemy to fly off to negative X, positive Y, and a small incremental positive Z vector and I have no clue why. From what I can tell my code here isn't telling it to move at all...? The reason why I suspect the code is because if I deactivate the script in the inspector the object doesn't go off on its magical journey. Also all my navmeshagents are off to the side of the actual objects and I don't know why. Is there a way to move the actual agent itself? Resetting didn't help I'll try deleting it and adding a new one. Edit, didn't help, still offset.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class enemyController : MonoBehaviour
{
[SerializeField]
private GameObject player;
public NavMeshAgent agent;
private float enemyDelayTime = 0f;
private void Start()
{
agent = gameObject.GetComponent<NavMeshAgent>();
agent.isStopped = false;
agent.updatePosition = false;
agent.updateRotation = false;
}
// Update is called once per frame
void Update ()
{
enemyDelayTime -= Time.deltaTime;
if (agent.isStopped == true)
{
if (enemyDelayTime <= 0)
{
//Debug.Log("successfully resumed");
agent.isStopped = false;
enemyDelayTime = 4f;
}
}
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag.Equals("Player"))
{
Debug.Log("successfully stopped");
agent.isStopped = true;
Debug.Log(enemyDelayTime);
Debug.Log(agent.isStopped);
}
}
}
Answer by Seldkam · Nov 03, 2018 at 06:30 PM
Annnnd fixed this one too lol. Turns out it was a Blender issue! Be careful where that orange dot is if you use blender-- that's where Unity thinks the navmesh should go, not the actual visual object. If you don't use blender I guess there's no need to worry? haha....