Hello,
so when i hit play it seems like my “AI” is moving randomly but then it runs right to the edge and stops moving and i can’t seem to figure out why any ideas?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class cellController : MonoBehaviour
{
public float timer;
public float newTarget;
public float speed;
public NavMeshAgent nav;
public Vector3 Target;
// Start is called before the first frame update
void Start()
{
nav = gameObject.GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
timer += Time.deltaTime;
if(timer >= newTarget)
{
NewTarget();
timer = 0;
}
}
void NewTarget()
{
float myX = gameObject.transform.position.x;
float myZ = gameObject.transform.position.z;
float xPos = myX + Random.Range(myX - 100, myX + 100);
float zPos = myZ + Random.Range(myZ - 100, myZ + 100);
Target = new Vector3 (xPos, gameObject.transform.position.y,zPos);
nav.SetDestination(Target);
}
}