Unity. What do angular joints mean?

I need to limit the rotation of the target ConfigurableJoint

to avoid distortion or destruction of the joint.

To see how angular works I did an experiment.

  • Place the humanoid model on the stage.
  • Add ConfigurableJoint

    to bone;
  • Add a script to manipulate the targetRotation

    Euler angles property .

    using UnityEngine;
    
    public class TestLimits : MonoBehaviour
    {
        [Range(-120, 120)]
        public float x;
        [Range(-120, 120)]
        public float y;
        [Range(-120, 120)]
        public float z;
        public Vector3 currentTorque; // to indicate limits
    
        private ConfigurableJoint j;
    
        void Start()
        {
            j = GetComponent<ConfigurableJoint>();
        }
    
        void Update()
        {
            j.targetRotation = Quaternion.Euler(x, y, z);
            currentTorque = j.currentTorque;
        }
    }
    
          

Having changed targetRotation

, we will see the limitation of joint movement.

As expected, the limitation is observed when the angles reach their extreme values. But not always. This only happens when the other two angles are zero. For example, if x = 91 and y = 89, the observed z-limits change in the direction of increase.

What does it mean? How to limit the rotation of the target?

+3


source to share


1 answer


I found the answer in Phisx documentation.

The spherical joint supports a taper constraint that constrains the angle between the X-axes of two constraint blocks. The X-axis of Axor1 is bounded by the limit cone, the axis of which is the x-axis of the actor0 action limitation frame. The allowed limit values ​​are the maximum rotation around the y and z axes of this block. Different y and z axes can be specified, in which case the limit takes the shape of an angular elliptical cone.

  • Both the y and z axes are the Actor0 axes. Therefore, we cannot use Euler angles.
  • The limit is an elliptical angular cone. Thus, the angles and are coordinated by the inequality 2 / a 2 + z 2 / b 2 1. Here a and b are limits.
  • It looks like the angular cone is rotating relative to actor0 around the twist axis.


This function limits rotation exactly to the limits of the joints.

private Quaternion targetRotation(ConfigurableJoint j, float x, float y, float z)
{
    // twist
    float angle = x;
    Vector3 axis = Vector3.right;

    if (angle > j.highAngularXLimit.limit)
        angle = j.highAngularXLimit.limit;
    if (angle < j.lowAngularXLimit.limit)
        angle = j.lowAngularXLimit.limit;
    Quaternion twist = Quaternion.AngleAxis(angle, axis);

    // swing
    angle = Mathf.Sqrt(y * y + z * z);
    axis = new Vector3(0, y, z);

    Vector3 t = twist * axis;
    float a = t.y / j.angularYLimit.limit;
    float b = t.z / j.angularZLimit.limit;
    float l = a * a + b * b;
    if (l > 1)
        angle = angle / Mathf.Sqrt(l);

    Quaternion swing = Quaternion.AngleAxis(angle, axis);

    return twist * swing;
}

      

+1


source







All Articles