diff options
| author | Guilherme Recchi Cardozo <gcardozo@esss.com.br> | 2018-10-24 16:32:55 -0300 |
|---|---|---|
| committer | Guilherme Recchi Cardozo <gcardozo@inf.ufsm.br> | 2018-11-01 06:41:34 -0300 |
| commit | 3fb2069d39b2ccfb30c06cffcf802d73ce169d60 (patch) | |
| tree | d33d96ede12e8d00fde999ae2979633c0fc55182 /scene/2d/physics_body_2d.cpp | |
| parent | d42fd8fa7936ab0f32e207063908cc41dc1ee7ab (diff) | |
| download | redot-engine-3fb2069d39b2ccfb30c06cffcf802d73ce169d60.tar.gz | |
Add method get_collision_exceptions
Adding this method to PhysicsBody, PhysicsBody2D and
SoftBody. It returns a list of nodes included in
collision exceptions.
Fixes #23235, cheers!
Diffstat (limited to 'scene/2d/physics_body_2d.cpp')
| -rw-r--r-- | scene/2d/physics_body_2d.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index d0bebd3354..60074abb29 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -32,8 +32,11 @@ #include "core/core_string_names.h" #include "core/engine.h" +#include "core/list.h" #include "core/math/math_funcs.h" #include "core/method_bind_ext.gen.inc" +#include "core/object.h" +#include "core/rid.h" #include "scene/scene_string_names.h" void PhysicsBody2D::_notification(int p_what) { @@ -65,6 +68,8 @@ void PhysicsBody2D::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_layers", "mask"), &PhysicsBody2D::_set_layers); ClassDB::bind_method(D_METHOD("_get_layers"), &PhysicsBody2D::_get_layers); + + ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &PhysicsBody2D::get_collision_exceptions); ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &PhysicsBody2D::add_collision_exception_with); ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &PhysicsBody2D::remove_collision_exception_with); ADD_PROPERTY(PropertyInfo(Variant::INT, "layers", PROPERTY_HINT_LAYERS_2D_PHYSICS, "", 0), "_set_layers", "_get_layers"); //for backwards compat @@ -134,6 +139,20 @@ PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : set_pickable(false); } +Array PhysicsBody2D::get_collision_exceptions() { + List<RID> exceptions; + Physics2DServer::get_singleton()->body_get_collision_exceptions(get_rid(), &exceptions); + Array ret; + for (List<RID>::Element *E = exceptions.front(); E; E = E->next()) { + RID body = E->get(); + ObjectID instance_id = Physics2DServer::get_singleton()->body_get_object_instance_id(body); + Object *obj = ObjectDB::get_instance(instance_id); + PhysicsBody2D *physics_body = Object::cast_to<PhysicsBody2D>(obj); + ret.append(physics_body); + } + return ret; +} + void PhysicsBody2D::add_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); |
