summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-11-30 20:50:04 +0100
committerGitHub <noreply@github.com>2017-11-30 20:50:04 +0100
commit581ee23a15c0316aec539a8ff5c282e8d37aa191 (patch)
tree7e299823c92fd063801615ab3628ca00c5e0df6e
parent9678231b109c333a5273325c8758241310cd27f4 (diff)
parent4bd4d13570b0a6877f901c31619fdff4689fd070 (diff)
Merge pull request #13408 from VinegarLove/13399-raycast_exclude
Ported 'Exclude Parent' from Raycast2D to Raycast
-rw-r--r--scene/3d/ray_cast.cpp35
-rw-r--r--scene/3d/ray_cast.h4
2 files changed, 39 insertions, 0 deletions
diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp
index aebdcaf183..faeb18691a 100644
--- a/scene/3d/ray_cast.cpp
+++ b/scene/3d/ray_cast.cpp
@@ -119,6 +119,29 @@ bool RayCast::is_enabled() const {
return enabled;
}
+void RayCast::set_exclude_parent_body(bool p_exclude_parent_body) {
+
+ if (exclude_parent_body == p_exclude_parent_body)
+ return;
+
+ exclude_parent_body = p_exclude_parent_body;
+
+ if (!is_inside_tree())
+ return;
+
+ if (Object::cast_to<CollisionObject>(get_parent())) {
+ if (exclude_parent_body)
+ exclude.insert(Object::cast_to<CollisionObject>(get_parent())->get_rid());
+ else
+ exclude.erase(Object::cast_to<CollisionObject>(get_parent())->get_rid());
+ }
+}
+
+bool RayCast::get_exclude_parent_body() const {
+
+ return exclude_parent_body;
+}
+
void RayCast::_notification(int p_what) {
switch (p_what) {
@@ -133,6 +156,13 @@ void RayCast::_notification(int p_what) {
} else
set_physics_process(false);
+ if (Object::cast_to<CollisionObject>(get_parent())) {
+ if (exclude_parent_body)
+ exclude.insert(Object::cast_to<CollisionObject>(get_parent())->get_rid());
+ else
+ exclude.erase(Object::cast_to<CollisionObject>(get_parent())->get_rid());
+ }
+
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -256,7 +286,11 @@ void RayCast::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &RayCast::set_collision_mask_bit);
ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &RayCast::get_collision_mask_bit);
+ ClassDB::bind_method(D_METHOD("set_exclude_parent_body", "mask"), &RayCast::set_exclude_parent_body);
+ ClassDB::bind_method(D_METHOD("get_exclude_parent_body"), &RayCast::get_exclude_parent_body);
+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclude_parent"), "set_exclude_parent_body", "get_exclude_parent_body");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "cast_to"), "set_cast_to", "get_cast_to");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
}
@@ -332,4 +366,5 @@ RayCast::RayCast() {
collision_mask = 1;
cast_to = Vector3(0, -1, 0);
debug_shape = NULL;
+ exclude_parent_body = true;
}
diff --git a/scene/3d/ray_cast.h b/scene/3d/ray_cast.h
index ca94580271..9fb1a1be67 100644
--- a/scene/3d/ray_cast.h
+++ b/scene/3d/ray_cast.h
@@ -48,6 +48,7 @@ class RayCast : public Spatial {
Set<RID> exclude;
uint32_t collision_mask;
+ bool exclude_parent_body;
Node *debug_shape;
Ref<Material> debug_material;
@@ -74,6 +75,9 @@ public:
void set_collision_mask_bit(int p_bit, bool p_value);
bool get_collision_mask_bit(int p_bit) const;
+ void set_exclude_parent_body(bool p_exclude_parent_body);
+ bool get_exclude_parent_body() const;
+
void force_raycast_update();
bool is_colliding() const;
Object *get_collider() const;