Close enought

This was my attempt, I didn’t think about checking if there were less than 2 corners, my bad.

As long as you did put the corner count check in there, that solution works perfectly.

I was curious about the need for this check so I started digging. In their (now “Legacy” 5.4) doc Unity has this check in the example as well, but does not go into why.

Without considering the graph theory it might be tempting to think “but there only needs to be one corner: the one I am moving to” but that is a trap! You are not your corners!

In my playing I found that not only is Unity always holding a 0th corner as the “current position”, but it isn’t guaranteed to be the exact position of the object:
soClose

Presumably they have similar safeguards in place to make sure everything doesn’t just moonwalk away. Either that or the NavMeshAgent is too busy staring at the stars to notice…

Yeah, I found the documentation from Unity not being very precise on it nor giving an example…

Things like:
Is corners[0] the same as transform.position from this navmesh agent object or is it already the waypoint one ahead, so the actual path’s length would have its first segment going between the object an corners[0] is a thing in particular that is not given.

In the end I would think it actually doesn’t matter since the calculation just serves as an estimation to decide whether we accept a path as being within the range we want the player to move on one go…
But it’s still something that should be discussed in the documentation…

Privacy & Terms