NPC Follow Roads HELP!

So, I need help making NPCs follow a road to a random destination. I have multiple roads ( all tagged roads) I need help finding a way for them to find and then follow a road and change roads if needed to get to destination. NPCs will spawn at different locations. Also, I can’t use NavMesh, because something about my map won’t allow it so I have to do it manually. Any Help?

Here is my code:

public Animator animator;

    public GameObject target;
    public GameObject destination;
    public float speed = 2f;
    Rigidbody rig;


    // Start is called before the first frame update
    void Start()
    {
        rig = GetComponent<Rigidbody>();

        animator = GetComponent<Animator>();

        target = GameObject.FindWithTag("Roads");

  
    }

    // Update is called once per frame
    private void FixedUpdate()
    {
        Vector3 pos = Vector3.MoveTowards(transform.position, target.transform.position, speed * Time.fixedDeltaTime);
        rig.MovePosition(pos);
    }

    public void OnCollisionEnter(Collision collision)
    {



        if (collision.gameObject.tag == "Roads")
        {
            RandomDestination();
            Vector3 pos = Vector3.MoveTowards(transform.position, destination.transform.position, speed * Time.fixedDeltaTime);
            rig.MovePosition(pos);
        }



    }

    public void RandomDestination()
    {
        int Des = Random.Range(0, 14);

        if (Des == 0)
        {
            destination = GameObject.Find("AionaTailoring");
        }
        else if (Des == 1)
        {
            destination = GameObject.Find("Clinic");
        }
        else if (Des == 2)

You get the point after this.

Either fix the navmesh issue or make your own solution. Maybe using splines?

You have to fix your navmesh problem or youll be pulling your hair out till your bald…

1 Like

+1 to that
It really sounds like you need to learn all the basics of using a navmesh in unity
I’d advise these videos as they cover everything you need to know to get started.

You quoted “I can’t use NavMesh, because something about my map won’t allow it”. Ok, are you using a terrain or a mesh?. We need more info to help…

1 Like

Agreed. I’d say make a new scene with just a flat plane and try baking a navmesh on that (trust me it’ll work :wink:
Next to thing to try is using something with a thickness.
I remember something in the past with trying to bake a navmesh on a mesh/terrain and it wasn’t working until I gave it a “thickness”, basically getting all the faces on the bottom and just extruding them down by something like 0.1.
If I didn’t do that then it wouldn’t bake (If my memory serves me correctly)

If baking a navmesh isn’t working then make sure you have every object that you want included in the baking marked as static.