Not sure why

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);
    }
}

I sometimes see similar behavior when I’ve forgotten to bake the navmesh. Make sure it’s baked first?

yes I baked it im not sure if this has anything to do with it but after baking i see 2 almost triangles coming from my “AI” character and it kinda follows one of them.

Maybe include a screenshot of what you’re seeing?

okay i am not sure what happened but i restarted unity and now its working 0_0 strange lol