diff options
-rw-r--r-- | scene/2d/joints_2d.cpp | 35 | ||||
-rw-r--r-- | scene/2d/joints_2d.h | 5 | ||||
-rw-r--r-- | scene/3d/physics_joint.cpp | 31 | ||||
-rw-r--r-- | scene/3d/physics_joint.h | 4 |
4 files changed, 70 insertions, 5 deletions
diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp index 1df936535f..adb2904a0a 100644 --- a/scene/2d/joints_2d.cpp +++ b/scene/2d/joints_2d.cpp @@ -111,6 +111,19 @@ real_t Joint2D::get_bias() const{ return bias; } +void Joint2D::set_exclude_nodes_from_collision(bool p_enable) { + + if (exclude_from_collision==p_enable) + return; + exclude_from_collision=p_enable; + _update_joint(); +} + +bool Joint2D::get_exclude_nodes_from_collision() const{ + + return exclude_from_collision; +} + void Joint2D::_bind_methods() { @@ -124,9 +137,14 @@ void Joint2D::_bind_methods() { ObjectTypeDB::bind_method( _MD("set_bias","bias"), &Joint2D::set_bias ); ObjectTypeDB::bind_method( _MD("get_bias"), &Joint2D::get_bias ); + ObjectTypeDB::bind_method( _MD("set_exclude_nodes_from_collision","enable"), &Joint2D::set_exclude_nodes_from_collision ); + ObjectTypeDB::bind_method( _MD("get_exclude_nodes_from_collision"), &Joint2D::get_exclude_nodes_from_collision ); + ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "node_a"), _SCS("set_node_a"),_SCS("get_node_a") ); ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "node_b"), _SCS("set_node_b"),_SCS("get_node_b") ); ADD_PROPERTY( PropertyInfo( Variant::REAL, "bias/bias",PROPERTY_HINT_RANGE,"0,0.9,0.001"), _SCS("set_bias"),_SCS("get_bias") ); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "collision/exclude_nodes"), _SCS("set_exclude_nodes_from_collision"),_SCS("get_exclude_nodes_from_collision") ); + } @@ -135,6 +153,7 @@ void Joint2D::_bind_methods() { Joint2D::Joint2D() { bias=0; + exclude_from_collision=true; } /////////////////////////////////////////////////////////////////////////////// @@ -173,7 +192,10 @@ RID PinJoint2D::_configure_joint() { SWAP(body_a,body_b); } else if (body_b) { //add a collision exception between both - Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid()); + if (get_exclude_nodes_from_collision()) + Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid()); + else + Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(),body_b->get_rid()); } RID pj = Physics2DServer::get_singleton()->pin_joint_create(get_global_transform().get_origin(),body_a->get_rid(),body_b?body_b->get_rid():RID()); Physics2DServer::get_singleton()->pin_joint_set_param(pj, Physics2DServer::PIN_JOINT_SOFTNESS, softness); @@ -245,7 +267,11 @@ RID GrooveJoint2D::_configure_joint(){ if (!body_a || !body_b) return RID(); - Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid()); + + if (get_exclude_nodes_from_collision()) + Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid()); + else + Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(),body_b->get_rid()); Matrix32 gt = get_global_transform(); Vector2 groove_A1 = gt.get_origin(); @@ -338,7 +364,10 @@ RID DampedSpringJoint2D::_configure_joint(){ if (!body_a || !body_b) return RID(); - Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid()); + if (get_exclude_nodes_from_collision()) + Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid()); + else + Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(),body_b->get_rid()); Matrix32 gt = get_global_transform(); Vector2 anchor_A = gt.get_origin(); diff --git a/scene/2d/joints_2d.h b/scene/2d/joints_2d.h index 908e3a158e..d468f3a6b5 100644 --- a/scene/2d/joints_2d.h +++ b/scene/2d/joints_2d.h @@ -42,6 +42,8 @@ class Joint2D : public Node2D { NodePath b; real_t bias; + bool exclude_from_collision; + protected: @@ -62,6 +64,9 @@ public: void set_bias(real_t p_bias); real_t get_bias() const; + void set_exclude_nodes_from_collision(bool p_enable); + bool get_exclude_nodes_from_collision() const; + RID get_joint() const { return joint; } Joint2D(); diff --git a/scene/3d/physics_joint.cpp b/scene/3d/physics_joint.cpp index 0cc72b28e5..f4facb7c3f 100644 --- a/scene/3d/physics_joint.cpp +++ b/scene/3d/physics_joint.cpp @@ -34,8 +34,15 @@ void Joint::_update_joint(bool p_only_free) { if (joint.is_valid()) { - if (ba.is_valid() && bb.is_valid()) - PhysicsServer::get_singleton()->body_remove_collision_exception(ba,bb); + if (ba.is_valid() && bb.is_valid()) { + + if (exclude_from_collision) + PhysicsServer::get_singleton()->body_add_collision_exception(ba,bb); + else + PhysicsServer::get_singleton()->body_remove_collision_exception(ba,bb); + + } + PhysicsServer::get_singleton()->free(joint); joint=RID(); ba=RID(); @@ -144,6 +151,19 @@ void Joint::_notification(int p_what) { } +void Joint::set_exclude_nodes_from_collision(bool p_enable) { + + if (exclude_from_collision==p_enable) + return; + exclude_from_collision=p_enable; + _update_joint(); +} + +bool Joint::get_exclude_nodes_from_collision() const{ + + return exclude_from_collision; +} + void Joint::_bind_methods() { @@ -156,10 +176,16 @@ void Joint::_bind_methods() { ObjectTypeDB::bind_method( _MD("set_solver_priority","priority"), &Joint::set_solver_priority ); ObjectTypeDB::bind_method( _MD("get_solver_priority"), &Joint::get_solver_priority ); + ObjectTypeDB::bind_method( _MD("set_exclude_nodes_from_collision","enable"), &Joint::set_exclude_nodes_from_collision ); + ObjectTypeDB::bind_method( _MD("get_exclude_nodes_from_collision"), &Joint::get_exclude_nodes_from_collision ); + ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "nodes/node_a"), _SCS("set_node_a"),_SCS("get_node_a") ); ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "nodes/node_b"), _SCS("set_node_b"),_SCS("get_node_b") ); ADD_PROPERTY( PropertyInfo( Variant::INT, "solver/priority",PROPERTY_HINT_RANGE,"1,8,1"), _SCS("set_solver_priority"),_SCS("get_solver_priority") ); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "collision/exclude_nodes"), _SCS("set_exclude_nodes_from_collision"),_SCS("get_exclude_nodes_from_collision") ); + + } @@ -167,6 +193,7 @@ void Joint::_bind_methods() { Joint::Joint() { + exclude_from_collision=true; solver_priority=1; } diff --git a/scene/3d/physics_joint.h b/scene/3d/physics_joint.h index a5f4ea4bdb..3f5a0e91a6 100644 --- a/scene/3d/physics_joint.h +++ b/scene/3d/physics_joint.h @@ -45,6 +45,7 @@ class Joint : public Spatial { NodePath b; int solver_priority; + bool exclude_from_collision; protected: @@ -67,6 +68,9 @@ public: void set_solver_priority(int p_priority); int get_solver_priority() const; + void set_exclude_nodes_from_collision(bool p_enable); + bool get_exclude_nodes_from_collision() const; + RID get_joint() const { return joint; } Joint(); |