The exmaple after reading the whole part of navmeshagent is in this link:
https://docs.unity3d.com/Manual/nav-AgentPatrol.html
In my Hierarchy i have a ThirdPersonController i added to it a NavMeshAgent.
Then added also the waypoints script to the ThirdPersonController.
In the Hierarchy i also have two Spheres as waypoints and Plane.
In the Window > Navigation in tab Object i set both two waypoints and the plane to be Navigation Static.
Then clicked on the Bake button and after some time the baking finished.
Dragged the waypoints to the script in the inspector.
Running the game the player was moving first time to the first waypoint then make a small round and moved to then ext waypoint small round to the start position and then back to the first waypoint but then the player got crazy in the second waypoint again moved strange to the first waypoint and there he is making none stopr rounds around the first waypoint. Strange movments.
The ThirdPersoncontroller walking speed in the animator i set it to 5.0 and created new state called it Walk with HumandoidWalk animation. Set this state as default so when running the game the player is start walking automatic.
Here is a small video clip i recorded showing the strange walking fo the player:
This is a screenshot of the scene after baked:
This is a screenshot of the hierarchy of the thirdpersoncontroller(1) inspector with the navmeshagent and the script attached:
And the waypoints script:
public Transform[] points;
private int destPoint = 0;
private NavMeshAgent agent;
// Use this for initialization
void Start () {
agent = GetComponent<NavMeshAgent> ();
agent.autoBraking = false;
GotoNextPoint ();
}
void GotoNextPoint()
{
if (points.Length == 0)
return;
agent.destination = points [destPoint].position;
destPoint = (destPoint + 1) % points.Length;
}
// Update is called once per frame
void Update () {
if (agent.remainingDistance < 0.5f)
GotoNextPoint ();
}
}
What i want to do is two things:
-
To fix the problem/s with this waiypoints script.
-
To make that when the player is getting to the first way point he will turn sharp facing to the second waypoint and will walk directly to the second waypoint in the path between the two waypoints. Same when getting to the second waypoint turn sharp facing to the startposition and then again to the first waypoint. Now what it does is making some round near the waypoints and realy patrolling between them.