Reputation: 11
I'm currently trying to do some pathfinding on Unity using NavMesh, for some reason though when I run the game it say that the agent is not close enough to the NavMesh (even though it's literally inside it).
I've added my code, and attached a few images to explain my issue better.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Fellas : MonoBehaviour
{
[SerializeField] Transform target;
NavMeshAgent agent;
private void start()
{
agent = GetComponent<NavMeshAgent>();
agent.updateRotation = false;
agent.updateUpAxis = false;
}
private void Update()
{
agent.SetDestination(target.position);
}
}
I've tried baking the NavMesh again, changing the size of the waypoint, bringing the waypoint closer to the character but nothing seemed to change. Help would be appreciated!
Edit: noticed the image's info isn't showing up (still new to how stackoverflow works) so just wanted to say that: the first picture shows the border of the NavMesh. The second is a closeup of the character and the waypoint and the third is just the errors I get.
Upvotes: 0
Views: 449
Reputation: 11
Figured out what I was doing wrong. I was using box colliders for my obstacles even though you don't need them. Whoopsies...
Upvotes: 0
Reputation: 1
This error occurs if the navmesh hasn't been created accurately, specifically the area where AI moves. Check if you've set up the navigation area correctly. This video might be helpful:
https://www.youtube.com/watch?v=HRX0pUSucW4
For the "Object reference not set" error, check if your navmeshagent is in the same object as the Fellas script.
If none of the above mentioned resolves the issue, I'd appreciate it if you could send me a few more project screenshots so I can get a better understanding of what's going on.
Upvotes: 0