summaryrefslogtreecommitdiff
path: root/modules/navigation
diff options
context:
space:
mode:
authorsmix8 <52464204+smix8@users.noreply.github.com>2022-06-23 19:16:47 +0200
committersmix8 <52464204+smix8@users.noreply.github.com>2022-06-23 23:32:05 +0200
commite57360d8df6329e1e547bc5717ee707a7620e039 (patch)
tree3f434c5d3e383bccc577a2d4abf24daf4f1cf4be /modules/navigation
parent462127eff08c8ca60a1e4a476153bdb60d63b890 (diff)
Add NavigationServer.region_owns_point() helper function
Adds a helper function to check if a world space position is currently owned by a navigation region.
Diffstat (limited to 'modules/navigation')
-rw-r--r--modules/navigation/godot_navigation_server.cpp10
-rw-r--r--modules/navigation/godot_navigation_server.h2
2 files changed, 12 insertions, 0 deletions
diff --git a/modules/navigation/godot_navigation_server.cpp b/modules/navigation/godot_navigation_server.cpp
index 927748dbd9..e243770cd2 100644
--- a/modules/navigation/godot_navigation_server.cpp
+++ b/modules/navigation/godot_navigation_server.cpp
@@ -351,6 +351,16 @@ real_t GodotNavigationServer::region_get_travel_cost(RID p_region) const {
return region->get_travel_cost();
}
+bool GodotNavigationServer::region_owns_point(RID p_region, const Vector3 &p_point) const {
+ const NavRegion *region = region_owner.get_or_null(p_region);
+ ERR_FAIL_COND_V(region == nullptr, false);
+ if (region->get_map()) {
+ RID closest_point_owner = map_get_closest_point_owner(region->get_map()->get_self(), p_point);
+ return closest_point_owner == region->get_self();
+ }
+ return false;
+}
+
COMMAND_2(region_set_navigation_layers, RID, p_region, uint32_t, p_navigation_layers) {
NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_COND(region == nullptr);
diff --git a/modules/navigation/godot_navigation_server.h b/modules/navigation/godot_navigation_server.h
index d4306e7931..48c8dcbeb2 100644
--- a/modules/navigation/godot_navigation_server.h
+++ b/modules/navigation/godot_navigation_server.h
@@ -117,6 +117,8 @@ public:
COMMAND_2(region_set_travel_cost, RID, p_region, real_t, p_travel_cost);
virtual real_t region_get_travel_cost(RID p_region) const override;
+ virtual bool region_owns_point(RID p_region, const Vector3 &p_point) const override;
+
COMMAND_2(region_set_map, RID, p_region, RID, p_map);
virtual RID region_get_map(RID p_region) const override;
COMMAND_2(region_set_navigation_layers, RID, p_region, uint32_t, p_navigation_layers);