gpt4 book ai didi

unity3d - 统一。关节角度限制是什么意思?

转载 作者:行者123 更新时间:2023-12-02 03:05:16 31 4
gpt4 key购买 nike

我需要限制 ConfigurableJoint 的目标旋转以避免关节变形或破坏。

为了了解角度限制的工作原理,我做了一个实验。

  1. 在场景中放置一个人形模型。
  2. 为骨骼添加ConfigurableJoint
  3. 添加脚本以通过欧拉角控制 targetRotation 属性。

    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;
    }
    }

改变 targetRotation 我们可以看到关节运动的限制。

正如预期的那样,当角度达到极限值时会观察到限制。但不总是。它仅在其他两个角度等于零时发生。例如,如果 x = 91 和 y = 89,观察到 z-limits 的变化方向增加。

这是什么意思?如何限制目标旋转?

最佳答案

我在 Phisx 中找到了答案 documentation.

The spherical joint supports a cone limit, which constrains the angle between the X-axes of the two constraint frames. Actor1's X-axis is constrained by a limit cone whose axis is the x-axis of actor0's constraint frame. The allowed limit values are the maximum rotation around the y- and z- axes of that frame. Different values for the y- and z- axes may be specified, in which case the limit takes the form of an elliptical angular cone.

  1. y 轴和 z 轴都是 Actor0 的轴。所以不能用欧拉角。
  2. 极限是椭圆角锥。所以 y 和 z 角受不等式约束 y2/a2 + z2/b2 < 1 . 这里 a 和 b 是极限。
  3. 然后看来角锥体围绕扭曲轴相对于 actor0 旋转。

此函数将旋转限制在关节限制范围内。

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;
}

关于unity3d - 统一。关节角度限制是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43226693/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com