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 Codelyy · Dec 16, 2015 at 03:23 AM · c#navmeshnavmeshagentenemyai

NavMeshAgent object jumps

I tried to set up a script that will have a enemy follow the player using the NavMesh agent whenever the player comes into a certain range and it works the way i want it too but problem seem to happen when i add the same prefab on the NavMesh.

I can't really tell what's happening but it seems the two prefabs with the NavMesh agents on the NavMesh will jump away from each other and then go back to roaming like they should but when they get close they will jump away from each other again. This also happen when i try to drag and drop a prefab with the NavMeshAgent next to another prefab with the component during the game is running, Unity won't let me move it any closer to the other prefab.

This is my script:

 // Update is called once per frame
     void Update () {
 
         NearPlayer();
         Roaming();
     }
 
     void NearPlayer()
     {
 
         if (Vector3.Distance(transform.position, player.transform.position) <= maxChaseDistance && Vector3.Distance(transform.position, player.transform.position) > maxAttackDistance)
         {
             inRange = true;
             if (inRange)
             {
                 agent.Resume();
                 agent.SetDestination(player.transform.position);
                 transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(player.transform.position - transform.position), moveSpeed * Time.deltaTime);
                 anim.Play("Chase");
             }
         }
 
         if (Vector3.Distance(transform.position, player.transform.position) <= maxAttackDistance)
         {
 
             agent.Stop();
             anim.Play("Attack");
         }
 
         if (Vector3.Distance(transform.position, player.transform.position) > maxChaseDistance)
         {
 
             inRange = false;
 
         }
 
     }
 
     void Roaming()
     {
         if (!inRange)
         {
             timer = timer - Time.deltaTime;
             if (timer < 0)
             {
                 timer = 2;
                 agent.SetDestination(randomDirection);
                 randomDirection = Random.insideUnitSphere * radius;
                 randomDirection.y = 0.0f;
                 randomDirection += startPosition;                           
             }
         }
     }

I'm guessing due to how unity won't let me drag and drop another prefab near the existing prefab means this isn't really a problem and something about the NavMesh stuff i don't understand.

Would anyone be able to tell me why this is happening and if there is any way around it?

Comment
Add comment
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

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

37 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Enemy freezes in NavMesh and starts attacking? [Duplicate] 0 Answers

Finding Closest Object Through Navmesh,Identifying Which Object Is Closest on NavMesh 0 Answers

Prevent NavMesh from Moving Diagonally? 1 Answer


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