Godot Version
4.6.2
Question
Hi everyone! I’m trying to get a random point from a nav mesh, but it needs to be inside the camera boundaries. The camera projection is set to orthogonal, so I believe it is like a box. How can I get this?
You can start by brute forcing it. Get random map points from the nav server and check each using Camera3D::is_position_in_frustum() until one passes the check.
I can see this working for this little environment in the picture, but as I create a larger stage, would that work?
Why wouldn’t it?
I mean, the nav mesh points possible would increase the larger the stage, no? What if all points generated by the loop are not in the camera boundaries?
Run an endless loop and exit when the point is found. Theoretically, it could happen that you’ll run for a long time but in practice I think you’ll hit something soon enough. Test and see.
If you want to make it more reliable, generate a uniform grid of positions that cover the entire map, shuffle them and get the nearest nav mesh point from the server for each of those points and test them against the camera frustum.
You can tighten even further by generating the grid only inside the frustum (or its ground projection if the map is mostly horizontal).