diff options
Diffstat (limited to 'scene/3d/physics_joint_3d.cpp')
-rw-r--r-- | scene/3d/physics_joint_3d.cpp | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/scene/3d/physics_joint_3d.cpp b/scene/3d/physics_joint_3d.cpp index af4d6ae152..06de5ad0ae 100644 --- a/scene/3d/physics_joint_3d.cpp +++ b/scene/3d/physics_joint_3d.cpp @@ -43,6 +43,7 @@ void Joint3D::_update_joint(bool p_only_free) { } if (p_only_free || !is_inside_tree()) { + warning = String(); return; } @@ -52,20 +53,47 @@ void Joint3D::_update_joint(bool p_only_free) { PhysicsBody3D *body_a = Object::cast_to<PhysicsBody3D>(node_a); PhysicsBody3D *body_b = Object::cast_to<PhysicsBody3D>(node_b); - if (!body_a && body_b) { - SWAP(body_a, body_b); + if (node_a && !body_a && node_b && !body_b) { + warning = TTR("Node A and Node B must be PhysicsBody3Ds"); + update_configuration_warning(); + return; } - if (!body_a) { + if (node_a && !body_a) { + warning = TTR("Node A must be a PhysicsBody3D"); + update_configuration_warning(); return; } - joint = _configure_joint(body_a, body_b); + if (node_b && !body_b) { + warning = TTR("Node B must be a PhysicsBody3D"); + update_configuration_warning(); + return; + } + + if (!body_a && !body_b) { + warning = TTR("Joint is not connected to any PhysicsBody3Ds"); + update_configuration_warning(); + return; + } - if (!joint.is_valid()) { + if (body_a == body_b) { + warning = TTR("Node A and Node B must be different PhysicsBody3Ds"); + update_configuration_warning(); return; } + if (!body_a) { + SWAP(body_a, body_b); + } + + warning = String(); + update_configuration_warning(); + + joint = _configure_joint(body_a, body_b); + + ERR_FAIL_COND_MSG(!joint.is_valid(), "Failed to configure the joint."); + PhysicsServer3D::get_singleton()->joint_set_solver_priority(joint, solver_priority); ba = body_a->get_rid(); @@ -137,6 +165,19 @@ bool Joint3D::get_exclude_nodes_from_collision() const { return exclude_from_collision; } +String Joint3D::get_configuration_warning() const { + String node_warning = Node3D::get_configuration_warning(); + + if (!warning.empty()) { + if (!node_warning.empty()) { + node_warning += "\n\n"; + } + node_warning += warning; + } + + return node_warning; +} + void Joint3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint3D::set_node_a); ClassDB::bind_method(D_METHOD("get_node_a"), &Joint3D::get_node_a); @@ -150,8 +191,8 @@ void Joint3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_exclude_nodes_from_collision", "enable"), &Joint3D::set_exclude_nodes_from_collision); ClassDB::bind_method(D_METHOD("get_exclude_nodes_from_collision"), &Joint3D::get_exclude_nodes_from_collision); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_a", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "CollisionObject3D"), "set_node_a", "get_node_a"); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_b", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "CollisionObject3D"), "set_node_b", "get_node_b"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_a", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "PhysicsBody3D"), "set_node_a", "get_node_a"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_b", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "PhysicsBody3D"), "set_node_b", "get_node_b"); ADD_PROPERTY(PropertyInfo(Variant::INT, "solver/priority", PROPERTY_HINT_RANGE, "1,8,1"), "set_solver_priority", "get_solver_priority"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision/exclude_nodes"), "set_exclude_nodes_from_collision", "get_exclude_nodes_from_collision"); @@ -669,9 +710,6 @@ void Generic6DOFJoint3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_flag_z", "flag", "value"), &Generic6DOFJoint3D::set_flag_z); ClassDB::bind_method(D_METHOD("get_flag_z", "flag"), &Generic6DOFJoint3D::get_flag_z); - ClassDB::bind_method(D_METHOD("set_precision", "precision"), &Generic6DOFJoint3D::set_precision); - ClassDB::bind_method(D_METHOD("get_precision"), &Generic6DOFJoint3D::get_precision); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_limit_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_LINEAR_LIMIT); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_x/upper_distance"), "set_param_x", "get_param_x", PARAM_LINEAR_UPPER_LIMIT); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_x/lower_distance"), "set_param_x", "get_param_x", PARAM_LINEAR_LOWER_LIMIT); @@ -760,8 +798,6 @@ void Generic6DOFJoint3D::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_spring_z/damping"), "set_param_z", "get_param_z", PARAM_ANGULAR_SPRING_DAMPING); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_spring_z/equilibrium_point"), "set_param_z", "get_param_z", PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT); - ADD_PROPERTY(PropertyInfo(Variant::INT, "precision", PROPERTY_HINT_RANGE, "1,99999,1"), "set_precision", "get_precision"); - BIND_ENUM_CONSTANT(PARAM_LINEAR_LOWER_LIMIT); BIND_ENUM_CONSTANT(PARAM_LINEAR_UPPER_LIMIT); BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_SOFTNESS); @@ -880,14 +916,6 @@ bool Generic6DOFJoint3D::get_flag_z(Flag p_flag) const { return flags_z[p_flag]; } -void Generic6DOFJoint3D::set_precision(int p_precision) { - precision = p_precision; - - PhysicsServer3D::get_singleton()->generic_6dof_joint_set_precision( - get_joint(), - precision); -} - RID Generic6DOFJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) { Transform gt = get_global_transform(); //Vector3 cone_twistpos = gt.origin; |