Support Forum

Best way of getting random point on a recast graph?

Hi there! I’m using a recast graph and moving my agents around in a 3D space with a simple random wander script where they search for a random point:

private Vector3 PickRandomPoint()
			Vector3 point = Random.insideUnitSphere * radius;
			point += aiPath.position;
			return point;

And then set the point as the new destiantion:

aiPath.destination = PickRandomPoint();

The issue I’m having is that the point is often at unreachable heights (y-axis).

I found some examples that simple zero out the Y-value but then I wouldn’t really get the verticality I want.

I basically want my agents to be able to find any valid position within an area, and then move there. The current system I have just has them find the closest valid position to the random point and I guess it works ok, but I’m wondering if there’s something a bit more precise.


Have you checked out this tutorial? Documentation

Thanks for the link, so for a recast graph I’d be looking at method 4? I’ll try it out!

4, or 5 would work.
5 is probably easier to implement.