diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp index adb8bdb29ba..a25d88cb39d 100644 --- a/scene/2d/joints_2d.cpp +++ b/scene/2d/joints_2d.cpp @@ -49,13 +49,13 @@ void Joint2D::_update_joint(bool p_only_free) { Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL; Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL; - if (!node_a || !node_b) + if (!node_a && !node_b) return; PhysicsBody2D *body_a = node_a ? node_a->cast_to() : (PhysicsBody2D *)NULL; PhysicsBody2D *body_b = node_b ? node_b->cast_to() : (PhysicsBody2D *)NULL; - if (!body_a || !body_b) + if (!body_a && !body_b) return; if (!body_a) { @@ -70,10 +70,10 @@ void Joint2D::_update_joint(bool p_only_free) { Physics2DServer::get_singleton()->get_singleton()->joint_set_param(joint, Physics2DServer::JOINT_PARAM_BIAS, bias); ba = body_a->get_rid(); - bb = body_b->get_rid(); + bb = body_b ? body_b->get_rid() : RID(); - if (exclude_from_collision) - Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid()); + if (exclude_from_collision && bb.is_valid()) + Physics2DServer::get_singleton()->body_add_collision_exception(ba, bb); } void Joint2D::set_node_a(const NodePath &p_node_a) { diff --git a/scene/3d/physics_joint.cpp b/scene/3d/physics_joint.cpp index 9c3b0d9c950..f93f9ede90f 100644 --- a/scene/3d/physics_joint.cpp +++ b/scene/3d/physics_joint.cpp @@ -47,13 +47,13 @@ void Joint::_update_joint(bool p_only_free) { Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL; Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL; - if (!node_a || !node_b) + if (!node_a && !node_b) return; PhysicsBody *body_a = node_a ? node_a->cast_to() : (PhysicsBody *)NULL; PhysicsBody *body_b = node_b ? node_b->cast_to() : (PhysicsBody *)NULL; - if (!body_a || !body_b) + if (!body_a && !body_b) return; if (!body_a) { @@ -68,10 +68,10 @@ void Joint::_update_joint(bool p_only_free) { PhysicsServer::get_singleton()->joint_set_solver_priority(joint, solver_priority); ba = body_a->get_rid(); - bb = body_b->get_rid(); + bb = body_b ? body_b->get_rid() : RID(); - if (exclude_from_collision) - PhysicsServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid()); + if (exclude_from_collision && bb.is_valid()) + PhysicsServer::get_singleton()->body_add_collision_exception(ba, bb); } void Joint::set_node_a(const NodePath &p_node_a) {