- Edited
Hello,I'm facing quite a tricky problem. I have a Navigation node with a Gridmap that contains a navmesh. My goal is to drop randomly spatial nodes (typically characters as rigidbody) all over the map, but not above the void (otherwise they fall). It must be on the ground of the gridmap.To do that, I created a node around which a random position is calculated within a given radius. Then I call [code]get_closest_point(random_point)[/code] of the Navigation node and I put my npc to this place.It does work well, but it causes a problem in some cases. All random points that are outside the navmesh will have a closest point at a border of the navmesh. And since the navmesh is made from a gridmap, there is no distance between the real border of the map and the border of the navmesh. And when the gridmap is designed to have walls all around the map, like in this screenshot:[img width=750 height=478]http://pix.toile-libre.org/upload/original/1469137014.png[/img]then the closest point of a point of the map would be right inside a wall. If you look at this image of a view from above: [url=http://pix.toile-libre.org/?img=1469137504.png][img width=361 height=360]http://pix.toile-libre.org/upload/img/1469137504.png[/img][/url]You see:[list type=decimal][li]The point generated randomly[/li][li]The closest point in the navmesh, where the npc rigidbody will be created.[/li][li]The point of the rigid body pushed by the wall (in red) thanks to the physics engine[/li][/list]And then the rigidbody falls from the map. I want to prevent that and be sure it will be dropped somewhere on a safe ground of the gridmap.I also tried to avoid the problem by comparing the position of the random point and the closest point, and if it's too far, calculate another random position. That does quite the trick but there are still some cases where the random point is exactly at the border of the navmesh, making then the rigidbody being pushed outside the map.And I can't use a cheap trick like killing all rigidbodies that fall too far away from the map. Some of those npc rigidbodies have the ability to float and they don't fall.Truly, I have no idea for the moment how to solve this problem. Does anyone have a suggestion?