Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AttencionGuy · Jul 13, 2018 at 05:31 PM · error3denemynavmeshagent

"SetDestination" can only be called on an active agent that has been placed on a NavMesh

So I'm making a 3d fps game. I was using @Brackeys tutorial - https://www.youtube.com/watch?v=xppompv1DBg just to add enemy. I checked my script 2 times, It's the same as in the video, i did all things correctly and got this error. I tried to press Window>Navigation and change some settings but it did not help me. Maybe this tutorial is not for 3D game, but i think it is. I'll be really thankful if someone will help. Thanks, here's my script public float lookRadius = 10f;

 Transform target;
 NavMeshAgent agent;


 // Use this for initialization
 void Start () {
     target = PlayerMAnager.instance.player.transform;
     agent = GetComponent<NavMeshAgent>();
 }
 
 // Update is called once per frame
 void Update () {
     float distance = Vector3.Distance(target.position, transform.position);

     if (distance <= lookRadius)
     {
         agent.SetDestination(target.position);

         if (distance <= agent.stoppingDistance)
         {
             FaceTarget();
         }
     }
 }

 void FaceTarget()
 {
     Vector3 direction = (target.position - transform.position).normalized;
     Quaternion lookRotation = (Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z)));
     transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * 5f);
 }

 private void OnDrawGizmosSelected()
 {
     Gizmos.color = Color.red;
     Gizmos.DrawWireSphere(transform.position, lookRadius);
 }

}

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Jul 13, 2018 at 06:03 PM 0
Share

so, what's the problem? I'm not going through that tutorial.

avatar image josiahsrc · Jul 13, 2018 at 08:13 PM 0
Share

Unity's Navmesh system is built for 3D games, so you're good. Two possible things that I see could be going wrong are: 1) You haven't baked a Navigation $$anonymous$$esh to the scene. This link should help if that's the case https://docs.unity3d.com/$$anonymous$$anual/nav-BuildingNav$$anonymous$$esh.html 2) You must either programmatically place the character on the Navmesh using a raycast or something, or simply drag the character close to the Navmesh. I hope this helps!

avatar image AttencionGuy josiahsrc · Jul 14, 2018 at 10:30 AM 0
Share

ok, first option helped me. Thanks a lot man :D

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by EddDom · Oct 25, 2020 at 05:51 PM

Well, you can go to Window > AI > Navigation and then configure which objects you want to be in the NavMesh (they have to be static). Then you can go to the Bake section of the tab, and click "Bake". Another thing is that make sure you place your player and enemies over the NavMesh. If they aren't, it will (probably) throw an error.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EddDom · Oct 25, 2020 at 05:53 PM 0
Share

Another thing is you might want to change target = Player$$anonymous$$Anager.instance.player.transform; to target = Player$$anonymous$$anager.instance.player.transform;

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

129 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Simple Enemy AI not working : NullReferenceException: Object reference not set to an instance of an object 2 Answers

Make an enemy follow along a wall 2 Answers

Tank not moving towards player 1 Answer

My enemy keeps shooting at me until I get close 1 Answer

how to add firerate to enemies shooting script 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges