瀏覽代碼

Added possibility to create joints with only one body

Andrea Catania 7 年之前
父節點
當前提交
b5480634c3
共有 1 個文件被更改,包括 6 次插入9 次删除
  1. 6 9
      scene/3d/physics_joint.cpp

+ 6 - 9
scene/3d/physics_joint.cpp

@@ -48,18 +48,14 @@ 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)
-		return;
-
 	PhysicsBody *body_a = Object::cast_to<PhysicsBody>(node_a);
 	PhysicsBody *body_b = Object::cast_to<PhysicsBody>(node_b);
 
-	if (!body_a || !body_b)
-		return;
-
-	if (!body_a) {
+	if (!body_a && body_b)
 		SWAP(body_a, body_b);
-	}
+
+	if (!body_a)
+		return;
 
 	joint = _configure_joint(body_a, body_b);
 
@@ -69,7 +65,8 @@ 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();
+	if (body_b)
+		bb = body_b->get_rid();
 
 	PhysicsServer::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision);
 }