diff --git a/doc/classes/JointLimitationCone3D.xml b/doc/classes/JointLimitationCone3D.xml
index 135135f50d..85ae1eb5fc 100644
--- a/doc/classes/JointLimitationCone3D.xml
+++ b/doc/classes/JointLimitationCone3D.xml
@@ -9,9 +9,9 @@
-
- The size of the hole made by the cone.
- [code]0[/code] is no hole, [code]0.5[/code] makes a hemisphere, and [code]1.0[/code] makes a sphere (no limitation).
+
+ The radius range of the hole made by the cone.
+ [code]0[/code] degrees makes a sphere without hole, [code]180[/code] degrees makes a hemisphere, and [code]360[/code] degrees become empty (no limitation).
diff --git a/scene/resources/3d/joint_limitation_cone_3d.cpp b/scene/resources/3d/joint_limitation_cone_3d.cpp
index bfbdd40ecf..e6e46cf4a7 100644
--- a/scene/resources/3d/joint_limitation_cone_3d.cpp
+++ b/scene/resources/3d/joint_limitation_cone_3d.cpp
@@ -30,20 +30,32 @@
#include "joint_limitation_cone_3d.h"
-void JointLimitationCone3D::set_radius_range(real_t p_radius_range) {
- radius_range = p_radius_range;
+#ifndef DISABLE_DEPRECATED
+bool JointLimitationCone3D::_set(const StringName &p_path, const Variant &p_value) {
+ // To keep compatibility between 4.6.beta2 and beta3.
+ if (p_path == SNAME("radius_range")) {
+ set_angle((float)p_value * Math::TAU);
+ } else {
+ return false;
+ }
+ return true;
+}
+#endif // DISABLE_DEPRECATED
+
+void JointLimitationCone3D::set_angle(real_t p_angle) {
+ angle = p_angle;
emit_changed();
}
-real_t JointLimitationCone3D::get_radius_range() const {
- return radius_range;
+real_t JointLimitationCone3D::get_angle() const {
+ return angle;
}
void JointLimitationCone3D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_radius_range", "radius_range"), &JointLimitationCone3D::set_radius_range);
- ClassDB::bind_method(D_METHOD("get_radius_range"), &JointLimitationCone3D::get_radius_range);
+ ClassDB::bind_method(D_METHOD("set_angle", "angle"), &JointLimitationCone3D::set_angle);
+ ClassDB::bind_method(D_METHOD("get_angle"), &JointLimitationCone3D::get_angle);
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius_range", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_radius_range", "get_radius_range");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "angle", PROPERTY_HINT_RANGE, "0,360,0.01,radians_as_degrees"), "set_angle", "get_angle");
}
Vector3 JointLimitationCone3D::_solve(const Vector3 &p_direction) const {
@@ -52,10 +64,10 @@ Vector3 JointLimitationCone3D::_solve(const Vector3 &p_direction) const {
Vector3 center_axis = Vector3(0, 1, 0);
// Apply the limitation if the angle exceeds radius_range * PI.
- real_t angle = p_direction.angle_to(center_axis);
- real_t max_angle = radius_range * Math::PI;
+ real_t current_angle = p_direction.angle_to(center_axis);
+ real_t max_angle = angle * 0.5;
- if (angle <= max_angle) {
+ if (current_angle <= max_angle) {
// If within the limitation range, return the new direction as is.
return p_direction;
}
@@ -65,7 +77,7 @@ Vector3 JointLimitationCone3D::_solve(const Vector3 &p_direction) const {
Vector3 plane_normal;
// Special handling for when the new direction vector is completely opposite to the central axis.
- if (Math::is_equal_approx((double)angle, Math::PI)) {
+ if (Math::is_equal_approx((double)current_angle, Math::PI)) {
// Select an arbitrary perpendicular axis
plane_normal = center_axis.get_any_perpendicular();
} else {
@@ -97,7 +109,7 @@ void JointLimitationCone3D::draw_shape(Ref &p_surface_tool, const T
if (sphere_r <= CMP_EPSILON) {
return;
}
- real_t alpha = CLAMP((real_t)radius_range, (real_t)0.0, (real_t)1.0) * Math::PI;
+ real_t alpha = CLAMP((real_t)angle, (real_t)0.0, (real_t)Math::TAU) * 0.5;
real_t y_cap = sphere_r * Math::cos(alpha);
real_t r_cap = sphere_r * Math::sin(alpha);
diff --git a/scene/resources/3d/joint_limitation_cone_3d.h b/scene/resources/3d/joint_limitation_cone_3d.h
index a9200864b1..98083c68a2 100644
--- a/scene/resources/3d/joint_limitation_cone_3d.h
+++ b/scene/resources/3d/joint_limitation_cone_3d.h
@@ -35,16 +35,19 @@
class JointLimitationCone3D : public JointLimitation3D {
GDCLASS(JointLimitationCone3D, JointLimitation3D);
- real_t radius_range = 0.25;
+ real_t angle = Math::TAU * 0.25;
protected:
+#ifndef DISABLE_DEPRECATED
+ bool _set(const StringName &p_name, const Variant &p_value);
+#endif // DISABLE_DEPRECATED
static void _bind_methods();
virtual Vector3 _solve(const Vector3 &p_direction) const override;
public:
- void set_radius_range(real_t p_radius_range);
- real_t get_radius_range() const;
+ void set_angle(real_t p_angle);
+ real_t get_angle() const;
#ifdef TOOLS_ENABLED
virtual void draw_shape(Ref &p_surface_tool, const Transform3D &p_transform, float p_bone_length, const Color &p_color) const override;