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?
//When there are more agents or obstacles is interesting.
This one worked very well thank you! But if you have an issue with your player model with this code, that it seems like it is stutttering while moveing to the destination just add and FixedUpdate() for it and call InstantlyTurn() there. This worked as solution for me!
Hello from the future! Just wanted to say thanks for this code snippet, the function works really well in my project. Also shout out to TowisGameLab for the FixedUpdate tip. Both of you are legends!
> Make sure that there are no compile > errors and that the file name and > class name match. This error seems to be related to another script you have thats trying to access a script named UIManager in order to add it to an object. So your issue is with another script in your project, not this one ive created. Create a new scene real quick to test on and drag the script here to an empty gameobject and press Play. Be sure to assign the variables that are in the inspector so you can test properly. Let me know what happens.
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.
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:
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.
This one worked very well thank you! But if you have an issue with your player model with this code, that it seems like it is stutttering while moveing to the destination just add and FixedUpdate() for it and call InstantlyTurn() there. This worked as solution for me!
– TowisGameLabHello from the future! Just wanted to say thanks for this code snippet, the function works really well in my project. Also shout out to TowisGameLab for the FixedUpdate tip. Both of you are legends!
– HoboMechanistic