Setting the destination

I finished the challenge before the last hints were revealed and I wonder, why would we be setting the navmesh’s destination directly and not use the provided method SetDestination()?
(I bet it actually doesn’t make a difference but I would regard using the method as being cleaner…)

Either method is appropriate.

NavMeshAgent.destination is a property you can set, but you do not get feedback if the destination was not a valid location on the NavMesh (more to the point, if the Agent was able to find a path along the NavMesh to that point).

NavMeshAgent.SetDestination() returns a boolean value, which returns true if it’s a valid destination and a path could be found, but false if there was no path.

I knew there would be a good reason to have SetDestination() over just having the property exposed. Determining if the destination is even valid makes a lot of sense.
OTOH if one could determine the path to it is only blocked temporarily (for example due to enemies being Navmesh obstacles that are in the way, or some door was closed) this might change any time…

This is largely handled by Mover.CanMoveTo(), which is usually called when the AI Controller sees that it is in range of the player. That being said, if the player is already spotted and Fighter is doing the chasing, then CanMoveTo() is not checked. In that event, however, the .destination will just fail quietly and the enemy should stand there.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms