summaryrefslogtreecommitdiff
path: root/scene/3d/navigation_obstacle_3d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d/navigation_obstacle_3d.cpp')
-rw-r--r--scene/3d/navigation_obstacle_3d.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/scene/3d/navigation_obstacle_3d.cpp b/scene/3d/navigation_obstacle_3d.cpp
index fa976e5d18..69fd5b02fc 100644
--- a/scene/3d/navigation_obstacle_3d.cpp
+++ b/scene/3d/navigation_obstacle_3d.cpp
@@ -36,7 +36,6 @@
#include "servers/navigation_server_3d.h"
void NavigationObstacle3D::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_navigation", "navigation"), &NavigationObstacle3D::set_navigation_node);
ClassDB::bind_method(D_METHOD("get_navigation"), &NavigationObstacle3D::get_navigation_node);
}
@@ -44,19 +43,19 @@ void NavigationObstacle3D::_bind_methods() {
void NavigationObstacle3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY: {
-
update_agent_shape();
// Search the navigation node and set it
{
- Navigation3D *nav = NULL;
+ Navigation3D *nav = nullptr;
Node *p = get_parent();
- while (p != NULL) {
+ while (p != nullptr) {
nav = Object::cast_to<Navigation3D>(p);
- if (nav != NULL)
- p = NULL;
- else
+ if (nav != nullptr) {
+ p = nullptr;
+ } else {
p = p->get_parent();
+ }
}
set_navigation(nav);
@@ -65,7 +64,7 @@ void NavigationObstacle3D::_notification(int p_what) {
set_physics_process_internal(true);
} break;
case NOTIFICATION_EXIT_TREE: {
- set_navigation(NULL);
+ set_navigation(nullptr);
set_physics_process_internal(false);
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
@@ -76,7 +75,6 @@ void NavigationObstacle3D::_notification(int p_what) {
PhysicsBody3D *rigid = Object::cast_to<PhysicsBody3D>(get_parent());
if (rigid) {
-
Vector3 v = rigid->get_linear_velocity();
NavigationServer3D::get_singleton()->agent_set_velocity(agent, v);
NavigationServer3D::get_singleton()->agent_set_target_velocity(agent, v);
@@ -86,9 +84,7 @@ void NavigationObstacle3D::_notification(int p_what) {
}
}
-NavigationObstacle3D::NavigationObstacle3D() :
- navigation(NULL),
- agent(RID()) {
+NavigationObstacle3D::NavigationObstacle3D() {
agent = NavigationServer3D::get_singleton()->agent_create();
}
@@ -98,16 +94,17 @@ NavigationObstacle3D::~NavigationObstacle3D() {
}
void NavigationObstacle3D::set_navigation(Navigation3D *p_nav) {
- if (navigation == p_nav)
+ if (navigation == p_nav) {
return; // Pointless
+ }
navigation = p_nav;
- NavigationServer3D::get_singleton()->agent_set_map(agent, navigation == NULL ? RID() : navigation->get_rid());
+ NavigationServer3D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid());
}
void NavigationObstacle3D::set_navigation_node(Node *p_nav) {
Navigation3D *nav = Object::cast_to<Navigation3D>(p_nav);
- ERR_FAIL_COND(nav == NULL);
+ ERR_FAIL_COND(nav == nullptr);
set_navigation(nav);
}
@@ -117,7 +114,6 @@ Node *NavigationObstacle3D::get_navigation_node() const {
String NavigationObstacle3D::get_configuration_warning() const {
if (!Object::cast_to<Node3D>(get_parent())) {
-
return TTR("The NavigationObstacle3D only serves to provide collision avoidance to a spatial object.");
}
@@ -151,8 +147,9 @@ void NavigationObstacle3D::update_agent_shape() {
radius *= MAX(s.x, MAX(s.y, s.z));
}
- if (radius == 0.0)
+ if (radius == 0.0) {
radius = 1.0; // Never a 0 radius
+ }
// Initialize the Agent as an object
NavigationServer3D::get_singleton()->agent_set_neighbor_dist(agent, 0.0);