How to get walkable info on NavMesh with mouse click?

Hi All

I want to implement a game, where you can drop your player character to the flat terrain using mouse click on a baked NavMesh for the terrain,
It’s a flat terrain with some unwalkable area like a pond or bushes.

But I want to make sure that the character can only be dropped on a valid terrain on NavMesh (not in the unwalkable area)
So, how do I get the information whether a point is walkable or unwalkable in a NavMesh?

I looked at the NavMesh.RayCast, and if I have to use it:

NavMesh.Raycast(source, target, hit, layerMask)

I Know the source is screen point mouse input,
but what is the target?
and what is the layer name of NavMesh?

thanks!

Use SamplePosition

NavMeshHit hit;
NavMesh.SamplePosition(Vector3, out hit, 5, 1 << NavMesh.GetNavMeshLayerFromName("Default"));

So use whatever you want to get the mouse click position then use that Vector3 in the Vector3 place above.

hit is the output so hit.position is the NavMesh position you’re after. 5 is the amount of units to check for a viable position.

All this does is check for the nearest viable position on the NavMesh given a Vector3 position.

Hope that makes sense, it’s getting late where I am!

Have a look into NavMesh.SamplePosition here NavMesh.SamplePositino
I’d suggest making a set of enums for the enemy ai, such as

public enum Action
{ Wandering, Idling, Fighting, Dying, Running, Seeking}
public Action activeAction;

Then on Update check for the current type, and do your stuff.
Obviously it would need some refining and creating a whole set of actions for him to perform, but I hope you get the idea I’m presenting.

Vector3 newPosition;
void Update()
{
if (activeAction == Action.Seeking)
   {
      if (Random.Range(0, 4) == 0)
      {
         newPosition = gameObject.transform.Position;
         newPosition.y -+ Random.Range(0, 20);
         if (SamplePosition(newPosition, NavMesh.FindObjectOfType<NavMesh>(), 15);
         {
            gameObject.MoveTo(newPosition);
           activeAction == Action.Wandering;
        }
      }
   }
   if (gameObject.transform.Position == newPosition && activeAction == Action.Wandering)
  {
      activeAction == Action.Seeking
   }
}