Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by sagicoh · Jul 02, 2014 at 12:09 AM · characterenemynavmeshnavmeshagent

NavMesh agent bug

I have an enemy and my character. Between them there is a wall. and the enemy should go around the wall to get to the character (using navMesh.setDestination() function), But he doesnt. he tries to go through the wall.

If I use any other empty object as the target of the navMesh the enemy goes around the wall. I tried changing the y position of the gameObject to see if its about the y but it didnt matter. Any help?? Thank you!

Here is the script:

 public float patrolSpeed = 2f;                          // The nav mesh agent's speed when patrolling.
 public float chaseSpeed = 5f;                           // The nav mesh agent's speed when chasing.
 public float chaseWaitTime = 5f;                        // The amount of time to wait when the last sighting is reached.
 public float patrolWaitTime = 1f;                       // The amount of time to wait when the patrol way point is reached.
 public Transform[] patrolWayPoints;                     // An array of transforms for the patrol route.
 
 
 private EnemyAnimation enemySight;                          // Reference to the EnemySight script.
 private NavMeshAgent nav;                               // Reference to the nav mesh agent.
 private Transform player;                               // Reference to the player's transform.
 private float chaseTimer;                               // A timer for the chaseWaitTime.
 private float patrolTimer;                              // A timer for the patrolWaitTime.
 private int wayPointIndex;                              // A counter for the way point array.
 
 
 void Awake ()
 {
     // Setting up the references.
     enemySight = GetComponent<EnemyAnimation>();
     nav = GetComponent<NavMeshAgent>();
     player = GameObject.FindGameObjectWithTag("Player").transform;
 }
 
 
 void Update ()
 {
 
     if(enemySight.InSight)

         Chasing();        

     else
         // ... patrol.
         Patrolling();
 }
 
 

 
 void Chasing ()
 {
     nav.SetDestination( player.transform.position) ;
     
 }
 
 
 void Patrolling ()
 {
     // Set an appropriate speed for the NavMeshAgent.
     nav.speed = patrolSpeed;
     
     // If near the next waypoint or there is no destination...
     if(!enemySight.InSight )
     {
         // ... increment the timer.
         patrolTimer += Time.deltaTime;
         
         // If the timer exceeds the wait time...
         if(patrolTimer >= patrolWaitTime)
         {
             // ... increment the wayPointIndex.
             if(wayPointIndex == patrolWayPoints.Length - 1)
                 wayPointIndex = 0;
             else
                 wayPointIndex++;
             
             // Reset the timer.
             patrolTimer = 0;
         }
     }
     else
         // If not near a destination, reset the timer.
         patrolTimer = 0;
     
     // Set the destination to the patrolWayPoint.
     nav.destination = patrolWayPoints[wayPointIndex].position;
 }
Comment
Add comment · Show 1
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 Ed unity · Jul 02, 2014 at 08:42 PM 0
Share

When you change the player to an empty game object, does the position, rotation, and scale stay the same? The player and the new gameObject should both be dynamic. They should not have NavmeshObstacle components and they should not be marked as static. If you are noticing that the NavAgent is still following the wrong path after checking that the above are true, I suggest filing a bug report. NavAgents should only traverse Walkable areas of the Navmesh, so unless the Wall is not creating a blocking path, there is a bug.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Enemy follow Camera 0 Answers

How to get a velocity unit vector from a NavMeshAgent? 1 Answer

Tank not moving towards player 1 Answer

Horde of NavMeshAgents - stops to recalculate path. 4 Answers

"Nav Mesh Agent" messes up simple prototype player-gameobject. What's up with that? 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