- Home /
Navmeshagent stops with destination set
For some reason when the units are moving they get stuck and collide at the edge of my concentric circle. When i click once and do nothing they clump up and never continue to the navmesh destination set from the info below...why do they stop and not continue to the location...if i put MovePlayerToDestination in update it works but obviously that would not be the way to do things. From my understanding both .SetDestination & .destination = should keep going until they have reached their destination why do they stop??? ulgh frustrating problem...:(
void MoveToMouse()
{
Plane plane = new Plane (Vector3.up, transform.position);
rayToMouse = Camera.main.ScreenPointToRay (Input.mousePosition);
float dist;
plane.Raycast (rayToMouse, out dist);
if (Physics.Raycast(rayToMouse, out hitTag))
{
//need owner check before interacting with planet options
//if (hit.transform.tag != "Planet")
MarkerGO.transform.position = hitTag.point;
}
MovePlayerToDestination();
}
public void MovePlayerToDestination()
{
for (int i = 0; i < GlobalLimit; i++)
{
if (PlayerUnitCache[i] != null && PlayerUnitCache[i].activeSelf)
{
if (MarkerUnits.Count > 1)
CreateConcentricCircles(i+1);
if (PlayerUnitCache[i].transform.position != MarkerUnits[i].transform.position)
{
if (MarkerUnits.Count > 1)
{
MarkerUnits[i].transform.position = new Vector3(pos.x+MarkerGO.transform.position.x, 0.012f, pos.y+MarkerGO.transform.position.z);
}
else if (MarkerUnits.Count == 1)
{
MarkerUnits[i].transform.position = MarkerGO.transform.position;
}
//SetDestination stops if something is blocking the path.
PlayerAgentCache[i].destination = MarkerUnits[i].transform.position;
}
}
}
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButton(0) && !RTSCamera.dragging)
{
Invoke("MoveToMouse", 0.12f);
}
else if(RTSCamera.dragging)
CancelInvoke("MoveToMouse");
}
Not really sure what's going on, but a few things about navmesh agents that might help you solve it (I'm assu$$anonymous$$g you're using Unity's built in NavmeshAgent:
-You can check for agent.remainingDistance, this should give you the remaining distance to the agent's destination.
-agent.path gives you an agent;s current path. You can check path.status to get it's status (PathComplete, PathPartial or PathInvalid). $$anonymous$$aybe your agents only have partial paths.
-You can use agent.CalculatePath to calculate a path for the agent to a destination without it actually moving there.
-You can also use path.corners to get all the corners of a path, you can use it to draw debug lines for your paths so you can see how the path goes (and where it ends).
Sorry, I don't really have an answer but I hope this helps you anyway.
Is there a way to force destination even if a path is blocked? If i put just:
for (int i = 0; i < GlobalLimit; i++)
{
if (PlayerUnitCache[i].transform.position.x != $$anonymous$$arkerUnits[i].transform.position.x && PlayerUnitCache[i].transform.position.z != $$anonymous$$arkerUnits[i].transform.position.z)
{
PlayerAgentCache[i].destination = $$anonymous$$arkerUnits[i].transform.position;
}
}
in update it does work
Not sure what you mean by 'forcing a destination if a path is blocked'. I suppose you could store the vector that you had set as destination, then check when your agent's remaining distance is 0 if it's at/near the destination you had set, and if not, do something (You could warp it to the destination you had set using NavmeshAgent.Warp for example.)
...Or maybe you should turn on agent.autoRepath? Have you read the NavmeshAgent API? Here's a link: http://docs.unity3d.com/ScriptReference/Nav$$anonymous$$eshAgent.html It really helps to read the documentation of these things.
Ya honestly i only know how to use destination when it comes to agent's i've never used any of the features you are talking about and don't really know how they work yet lol I tried autorepath it didn't do anything noticeable. I tried a distance check and the units do not reach their destination at least now i know it isn't a problem with them going to the wrong location...
Answer by Ziron999 · Feb 20, 2015 at 07:50 PM
Answered my own question it's because the waypoint destinations had a collision sphere on them...apparently this was just enough for the units to hit the sphere and then stop but if navmeshagent destination is in update i guess it forces the navmesh to go through a collision. Deleted the collision sphere and it works fine luckily they are just waypoints and don't need a collision anyway in this case...
Your answer
Follow this Question
Related Questions
NavMeshAgent object jumps 0 Answers
How to queue NavMeshAgents on entering a tile in Unity (based on path distance to tile)? 0 Answers
How to prevent NavMeshAgents from colliding when warped to same position? 0 Answers
NavMeshAgent resume original position and facing direction C# 0 Answers
How to make NavMeshAgents traverse two possible paths 1 Answer