0 votes

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.

Godot version 3.3
in Engine by (188 points)

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

1 Answer

0 votes
Best answer

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.getsimplepath(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.

by (60 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.