Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Seyren · Apr 13, 2016 at 01:12 PM · navmeshagentturning

Instantly Turn with Nav Mesh Agent

I've been testing Nav Mesh Agent and i really like it because of it's auto route system, but i can't get a good movement system with it.

I've tried a lot of values but i can't get a responsive movement for it, Specially when i set a new position while it's moving, doing some kind of ice skating and drifting to the next destination.

I would like to Instantly turn the navigator to the new directlion i clicked the character to move to (It's a click and move game), But i can't manage that by changing values in the inspector.

Do i have to do a code just to achieve that or is it a proper way to do so?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Barrrettt · Apr 25, 2017 at 05:13 AM

The solution for me: Manually control the rotation.

public class AgentControler: MonoBehaviour {

 private NavMeshAgent agent;
 private const float rotSpeed= 20f;

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

 void Update() {
     InstantlyTurn(agent.destination);
 }

 private void InstantlyTurn(Vector3 destination) {
     //When on target -> dont rotate!
     if ((destination - transform.position).magnitude < 0.1f) return; 
     
     Vector3 direction = (destination - transform.position).normalized;
     Quaternion  qDir= Quaternion.LookRotation(direction);
     transform.rotation = Quaternion.Slerp(transform.rotation, qDir, Time.deltaTime * rotSpeed);
 }

//note: We can return the rotation control to the agent when it moves. for example:

agent.updateRotation = ((agente.velocity).magnitude > 0.2);

//When there are more agents or obstacles is interesting.

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
2

Answer by chadwickhynes · Nov 09, 2020 at 02:42 PM

I did the opposite of what others suggested, jack the acceleration way up (I did 999, though I didn't find the min value to make it work).

Speed = 20 (whatever you want here) Angular Speed = 999 Acceleration = 999 Stopping Distance = 0 Auto Braking = True

That seemed to work for me

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 Dogmeat137 · Dec 01, 2020 at 09:32 AM 0
Share

Amazing, this worked for me haha

avatar image
1

Answer by RiQQ92 · Apr 14, 2016 at 12:10 PM

Best approach would probably be, is to write your own little method to turn your object towards NavAgent's first turn point.

First use NavAgent to calculate the path and then use the path's waypoints to determine where your object should turn, after your turning method send the agent on its way.

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 kevojo · May 12, 2017 at 05:28 PM

You can always turn the rotation speed of the navmeshagent way up: the faster this is, the faster it rotates towards destination. This combined with turning acceleration down a bit might be a simple way to solve this problem. if the acceleration is low, it will take longer for the object to get moving, this was how I personally fixed the issue.

With regards to animation, you might want to make a check that the object is moving a certain speed (check the vector3.distance(newpos, oldpos) ) before playing something like a walking animation. Maybe something like:

float distance = vector3.distance(newpos, oldpos); if (vector3.distance(navmeshagent.destination.point, gameobject.transform.position) > 0.5f && distance < 0.5f){ animation.play("turning"); } else if (vector3.distance(navmeshagent.destination.point, gameobject.transform.position) > 0.5f && distance < 0.5f){ animation.play("running"); } else animation.play("idle");

I'm still trying to figure out a way to find which absolute direction the navmeshagent is rotating in. Hard because when it rotates 360 degrees it switches from negative to positive, visa versa.

anyways hope this helps!

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

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

46 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

Related Questions

Smoothing Moves issue. 0 Answers

Pathfinding with specific end-direction and turning speed limit 0 Answers

Multiplayer Rotation is really slow 1 Answer

Angle Between vectors in Navigation Mesh 1 Answer

navmesh agent priority or weight 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