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 /
  • Help Room /
avatar image
0
Question by kylenoll123 · Oct 30, 2015 at 07:24 AM · navmeshnavigationenemyaienemy-ai

Enemy stops where player spawn (Navigation help)

I baked a NavMesh and all that jazz and added a script for my "zombies" to go to my destination, but they just go to where I spawned and stand there?

My code on the enemy is:

     public Transform Player;
     
     void Update()
     {
         GetComponent<NavMeshAgent>().destination = Player.position;
     }

They navigate correctly, avoiding obstacles and all, but just stop at my spawn position. The "Zombies" are prefabs if that matters and my player is also a prefab. Any help would be greatly appreciated!

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 insominx · Oct 30, 2015 at 03:31 PM 0
Share

Does your player position ever change? What is it exactly that you expect to happen?

avatar image kylenoll123 insominx · Oct 30, 2015 at 06:45 PM 0
Share

Yes, my player is moving using WASD. I expect the enemy to follow the player as he moves around the Nav$$anonymous$$esh. Thanks for the reply! Hopefully I can get this figured out because it's annoying how many hours I've spent on it haha! @inso$$anonymous$$x

avatar image insominx kylenoll123 · Oct 30, 2015 at 07:55 PM 0
Share

Your code looks like it should work. Is the value for Player.position changing? $$anonymous$$aybe the "Player" transform is the parent of thing doing the moving?

1 Reply

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

Answer by Taxen0 · Oct 30, 2015 at 07:41 PM

Try using the following:

 public Transform Player;
 private NavMeshAgent agent;

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

  
  void Update()
  {
      agent.SetDestination(Player.position);
  }

I would also recommend only to update when the player actually moves instead of in update.

Hope it helps!

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 kylenoll123 · Oct 30, 2015 at 08:53 PM 0
Share

I somehow resolved the issue by doing the following:

 public Transform Player;
     
     void Update()
     {
         Player = GameObject.FindGameObjectWithTag("Player").transform;
         GetComponent<Nav$$anonymous$$eshAgent>().destination = Player.position;
     }

Thank you both for you replies though!!

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

33 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

Related Questions

Navmesh Agent for direction but not movement? 0 Answers

Best way of creating unity car ai that wonders around searching for player 1 Answer

How to get a random point in the middle of nav mesh? 0 Answers

NavMeshLink don't work in correctly in certain area 0 Answers

Problem with NavMesh 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