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 Topthink · Dec 15, 2016 at 05:56 PM · mousenavmeshagentnavigationnav mesh

Can't Give Click to Move to Nav Mesh Agent ?!?

I created this Click-to-move script for my NavMeshAgent but it doesn't seem to work properly.

It will occasionally move to my click location. But, usually, my NavMeshAgent will do nothing. Sometimes I have to "click" 20 times over the course of many seconds and it just sits there. Sometimes it will move on the first click.

I've checked my mouse and it seems to be working properly. Can't figure it.

Here's the code if that helps: {

 public Vector3 GoToAllyPoint;
 NavMeshAgent agent;

 void Start ()
 {
     agent = GetComponent<NavMeshAgent> ();
 }

 void Update ()
 {

     if (Input.GetMouseButtonDown(0))
     {
         
         RaycastHit hit;

         if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity))
         {
             agent.SetDestination(hit.point);        
         }
     }
 }

}

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 Topthink · Dec 15, 2016 at 07:10 PM 0
Share

I stripped off every component I could and I still get the same problem. Hmmm.

I was thinking it may be because I'm setting the destination inside an Update but that is the same way the example in the manual shows it...from inside an update(). Hmmmm.

Still working on it. Can't figure it out yet.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Topthink · Dec 15, 2016 at 07:54 PM

Okay, I re-baked it using different settings. Works fine now.

I have no idea why.

But it works exactly as I want it to now.

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

Answer by Remjie · Dec 16, 2016 at 01:45 PM

Hi @Topthink, i was trying you code and everythings is fine. Dont you forget to bake the navmesh maybe?

Try something : open new project, add a plane, bake his navmesh then create a capsule, add it a navmeshagent and your script, and so tell us if that work with this few component.

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 Topthink · Dec 16, 2016 at 04:27 PM 0
Share

I got it to work as it was coded above but I had to re-bake it first. I'm not sure what the problem was. I baked it the first time...not sure what happened there. I actually baked it a couple more times with different settings and when I tried it again, it worked fine.

It might be something I did or didn't do. But it is fine now.

Thanks for your help.

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

63 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

Related Questions

How would I simulate a rectangular Nav Mesh Agent? 0 Answers

Navigation - NavMesh Agent - Only Humanoid AgentType Is Working 3 Answers

Unity Navagation Ground Mapping 1 Answer

NavMesh issue with spawning players 3 Answers

Navmesh Agent "move back" when player comes to close? 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