Random point on nav mesh

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Vikrant

I want to get random point on nav mesh in 3d space to implement random movement of enemy. I need on point on nav mesh so that enemy can navigate to it.

I generated random point but how to verify that this random point is on nav mesh

Vikrant | 2021-05-20 13:24

:bust_in_silhouette: Reply From: ferobregon

Im using random movement with navigation. I get a random position within a radius

var radius = 3
var random_position = Vector3(rand_range(-radius, radius), 0, rand_range(-radius, radius))

I then use the navigation.get_simple_path(random_position) to calculate the path and move the object to follow such path. I dont evaluate if the position collides with the mesh and the character never leaves the mesh on his movement.
I guess that if you need to evaluate the position you could use a raycast to check if the selected position collides with the navmesh.

but can you specify how to use raycast to check this.

Vikrant | 2021-05-22 16:09