thanks this helped me with my issue too
Sir I’m using Unity 2019.4 version. But player rotates insted of moving towards the target.
MY SCRIPT
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Mover : MonoBehaviour
{
[SerializeField] Transform target;
// Start is called before the first frame update
// Update is called once per frame
void Update()
{
GetComponent<NavMeshAgent>().destination = target.position;
}
}
Sir help me with this pls.
We’ll start by checking your Animator. Make sure that the Apply Root Motion is unchecked.
I spent about 1 hour banging my head against the wall on this.
When dragging enemies into the game, they appear to be hovering in the air just above the NAVMESH.
I found there’s a setting hidden under ADVANCED when baking the NAVMESH…it’s a setting called HEIGHT MESH.
After checking this box, and re-BAKING, the player/enemies are placed correctly.
Hi all I completet the lesson 11 but I have this error
“SetDestination” can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:set_destination(Vector3)
Mover:Update() (at Assets/Scripts/Mover.cs:13)
My Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Mover : MonoBehaviour
{
[SerializeField] Transform target;
// Update is called once per frame
void Update()
{
GetComponent<NavMeshAgent>().destination = target.position;
}
}
resolved I let active the mash
TIP : You can annotate your class, which will automatically add the nav mesh agent component to any game object on which you add your mover script.
[RequireComponent(typeof(NavMeshAgent))]
For anyone interested in a side quest, Unity has some unofficial official Nav Mesh Components that allow for some awesome control over how the Nav Mesh can be created. Here’s a video on where to download them and an overview on how to use them:
Brackey’s has a great video tutorial on the Nav Mesh Components as well.
Hi Rick/ everyone,
I am returning here from later on in the course and am trying to improve the nav mesh functionality on my enemies.
I am trying to make it so that the nav mesh agent in an enemy knows to walk around another enemy.
I initially tried to do this by adding a nav mesh obstacle onto each enemy, but that caused them to glitch - probably because there is a nav mesh agent and nav mesh obstacle on the same object.
I was wondering if anyone knew a way around this problem?
How can I make an object a nav mesh obstacle to other objects but not an obstacle to itself?
Thanks
The system should factor Agents in already… Try increasing obstacle avoidance in the NavMeshAgents.
Hi, I’m having a similar problem to a few people I saw post on here. The mod pack that you guys are using, I’m using a “brother/sister” pack from the same people in this video. No buildings/prefabs are showing up in unity with the baking so my character is just walking right thro everything. I have the same coding in the scripts, just my assets aren’t registering. Any fixes? I tried saving and reopening and it didn’t work. I am using unity 2020.3.14f1
Any help would be appreciated, possible to chat with someone to trouble shoot maybe for a fix?
Make sure that your buildings and other assets are marked as Static in the inspector. Also, with the object selected, click on the Navigation Tab, then the Object Tab under that, and set the Navigation Static to true. Set the Navigation Area to Walkable.
With some assets, this will still fail to work properly. With those, I find adding a box collider shaped to the asset helps.
Quick question on the Mover.cs script: wouldn’t we want to grab the NavMeshAgent component ONCE, in Start, instead of “re-grabbing” it every time in update? I thought GetComponent was supposed to be expensive… is there a reason it’s done this way? I did the following, which seemed to work:
void Start()
{
agent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
agent.destination = navTarget.transform.position;
}
Thanks for any and all feedback!
Zeb
Yes, actually most components that you reference on the same GameObject as the script can be cached in this way. The one thing I would change is that it’s good practice to cache your references to othe components in Awake() instead of Start(). This isn’t a huge deal here, but in other classes it’s make or break, so it’s a good habit to be in.
Awesome, thanks so much!
Not sure why my player isn’t moving to target can’t figure out if its in the code or if i did something wrong components its hard for me cause im starting with this set of videos and unity know nothing about coding or programing thought this would be a good way to learn now im stuck
Hi Kyle,
While we do try to keep things as simple as possible in the early lectures, it is an Intermediate course. It might be helpful to try one of the two intro courses (We have one 2D and one 3D, they both get you up to speed on Unity, C# and programming concepts).
In the meantime, let’s see if we can get your player moving to that target!
Let’s start with pasting in your Mover script.
It will also be helpful to take a look at your player’s inspector, to see if the right components are in place. You can collapse them so the titles of the components all fit in the inspector before taking a screenshot of the inspector window.
Just noticed while trying to add the first script that I have tons of errors from the imported files… Any advice on how to fix this? I think the errors are blocking the scripts from loading so I cant do anything. Im using unity 2018.3.14f1
The errors that are showing are not blocking, and can be safely ignored. … but there are 5 actual errors (the red messages). Click on the Triangle with the 24 next to it to hide the warnings, and then you’ll just see the red errors.