• 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 gianakos94 · 4 days ago · positionnavmeshagent

NavMesh Agent is changing my position of gameObject

Hello guys. I have a situation with my game. I am using ARFoundation , i am scaning a floor with PlaneManager and i am placing a prefab which is my whole level. When i placed the prefab time scale is 0 and all are in the right position. I have a PLAY button on my screen which i just change the timeScale and a starts some coroutines. When i press Play the ''enemies'' jumps to a different Y position.

I try to use gravity ,or initialize Enemies position nothing works. The enemies they haven't animation or changing position in some Start() method. When i disable NavMesh Agent the enemies are in the right position but they can't move of course. This is the Awake() code:

 void Awake()
 {
     GetComponent<AudioSource>().playOnAwake = false;

     agent = GetComponent<NavMeshAgent>();

     // Disabling auto-braking allows for continuous movement
     // between points (ie, the agent doesn't slow down as it
     // approaches a destination point).
     agent.autoBraking = false;
     agent.speed = 0.5f;

     checkEnemy = 1;
     timepassed2 = tenSec2 * 1;

     //Set the PlayerHealth
     currentHealth = maxHealth;
     healthBar.SetMaxHealth(maxHealth);

     //Using Warp for change with serialized field the position but it's not working
     agent.Warp(startPosition);
     print(transform.position);

 }


Any thoughts??? HELP <3

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

2 Replies

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

Answer by MickyX · 4 days ago

Are you placing the prefab at run time? Navmeshagents require a baked navmesh.

My guess is they are jumping to the baked navmesh position. Check you navmesh bake, and look into generating your navmesh at runtime if you are placing the prefab at runtime.

Comment
Add comment · Show 2 · 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 gianakos94 · 4 days ago 0
Share

Thanks for the fast answer. I baked the navMesh inside the prefab lvl but i don't know if the baking worked. When i run it on Unity it works fine. I disable the prefab on Unity Editor otherwise if my scene have only the ARcamera and Session Origin i have problem wtih NavMesh. He can't calculate the distance.

So how i can bake on runtime?any suggestions? Thanks a lot

avatar image MickyX gianakos94 · 4 days ago 0
Share

You should be able to see the navmesh by opening "Windows / Panels / Navigation "

Which will then display a blue visual for the baked navmesh so you can see where it is

In terms of baking at runtime its not something I've ever had to do but a quick google search gave me this by unity [https://learn.unity.com/tutorial/runtime-navmesh-generation][1] so that might be able to help further

avatar image
0

Answer by gianakos94 · 4 days ago

Man |@MickyX THANKS A LOT it worked out!!! YOU SAVED ME THANKS AGAIN . I download the NavMesh Componets from GitHub. i add NavMesh Surface on thew prefab-lvl and i added public NavMeshSurface surface;

and at start() method surface.BuildNavMesh();

and it worked!

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 MickyX · 4 days ago 0
Share

Excellent, glad you got it working, well done

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

168 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 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

Nav Mesh problem~ I need help! 0 Answers

NavMeshAgent stops when player is in inaccesible area 1 Answer

navmesh.sampleposition works strangely, what is going on here? 0 Answers

Navmesh agent teleporting 3 Answers

Camera rotation around player while following. 6 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