diff options
Diffstat (limited to 'scene/3d/ray_cast.cpp')
-rw-r--r-- | scene/3d/ray_cast.cpp | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp index 9f61cc64ea..faeb18691a 100644 --- a/scene/3d/ray_cast.cpp +++ b/scene/3d/ray_cast.cpp @@ -58,11 +58,6 @@ uint32_t RayCast::get_collision_mask() const { return collision_mask; } -void RayCast::set_type_mask(uint32_t p_mask) { - - type_mask = p_mask; -} - void RayCast::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); @@ -78,11 +73,6 @@ bool RayCast::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } -uint32_t RayCast::get_type_mask() const { - - return type_mask; -} - bool RayCast::is_colliding() const { return collided; @@ -129,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) { @@ -143,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: { @@ -187,7 +207,7 @@ void RayCast::_update_raycast_state() { PhysicsDirectSpaceState::RayResult rr; - if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask, type_mask)) { + if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask)) { collided = true; against = rr.collider_id; @@ -266,13 +286,13 @@ 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_type_mask", "mask"), &RayCast::set_type_mask); - ClassDB::bind_method(D_METHOD("get_type_mask"), &RayCast::get_type_mask); + 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"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "type_mask", PROPERTY_HINT_FLAGS, "Static,Kinematic,Rigid,Character,Area"), "set_type_mask", "get_type_mask"); } void RayCast::_create_debug_shape() { @@ -344,7 +364,7 @@ RayCast::RayCast() { collided = false; against_shape = 0; collision_mask = 1; - type_mask = PhysicsDirectSpaceState::TYPE_MASK_COLLISION; cast_to = Vector3(0, -1, 0); debug_shape = NULL; + exclude_parent_body = true; } |