Home > database >  unity 2020.3 NavMesh AI not moving
unity 2020.3 NavMesh AI not moving

Time:01-07

so this issue is fixed, the problem was that the U in Update wasnt capitalised

me and a few friends started making a FPS a few weeks ago and I'm now trying to get the AI to just walk towards the player but the enemy just stands still like a random object.

I have tried to rewrite the code, redo the NavMesh, redo the player and enemy components (with help from my brother who is an indie dev), I followed unity's documentation, even tried to do the AI in a different project but it just doesn't work.

I don't get any errors, so I don't know what I'm doing wrong, been at this AI for a day or two now

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class PlayerNavMesh : MonoBehaviour{

private NavMeshAgent agent;
private GameObject target;

private void Start()
{
    agent = GetComponent<NavMeshAgent>();
}


private void update() {
    target = GameObject.FindGameObjectWithTag("Player");



    if(target != null)
    {
        agent.destination = target.transform.position;
    }
    else
    {
        Debug.Log("No target found");
    }

}

}

CodePudding user response:

Update() should be capitalized. Also, why are you setting target every frame?

  •  Tags:  
  • Related