- Home /
Question by
BigHandInSky · Sep 13, 2016 at 10:15 AM ·
navmeshagentnavigationpaths
NavMeshAgent.SetPath not changing to new path?
Hey all,
I'm having a weird issue where my NavMeshAgent is not changing to my new path I'm calculating, where my goal is to take the path created when the agent enables, fuzzy it to get movement variation, then set agent to follow the fuzzied path, here's my code:
public class AiFuzzyNavMover : AiNavMover
{
// is called by inherited script on an interval
protected override IEnumerator ShiftNavMover()
{
Debug.Log("AiFuzzyNavMover[" + name + "]: ShiftNavMover triggering");
// disable shifting after this first calculation
CanShift = false;
// save path into local variable
NavMeshPath newPath = p_Agent.path;
int pathLength = newPath.corners.Length;
for (int corn = 0; corn < pathLength; corn++)
{
// skip first corner and last corner
if (( corn == 0 ) || ( corn + 1 >= pathLength ))
{
continue;
}
// get relevant corners and alter current
newPath.corners[corn] = AlterCorner(
newPath.corners[corn - 1],
newPath.corners[corn],
newPath.corners[corn + 1]);
}
// apply new path to agent
p_Agent.SetPath(newPath);
p_Agent.Resume();
yield break;
}
protected virtual Vector3 AlterCorner(Vector3 last, Vector3 curr, Vector3 next)
{
/* actual altering code commented out for now */
curr = (curr + Vector3.back * 2.0f);
return curr;
}
}
For whatever reason my agent doesn't switch to the new path, where SetPath is always returning true?
Comment