代码之家  ›  专栏  ›  技术社区  ›  tmighty

检查员显示哪个旋转?

  •  1
  • tmighty  · 技术社区  · 6 年前

    瞄准时,我的球员的胸骨可以旋转。

    现在我想评估一下我应该让胸部旋转多少(最小和最大旋转)。

    为了做到这一点,我允许所有的旋转角度,并看了一眼检查员。

    例如,胸部向左旋转的最小值应该是y=-15。 在y=-15(在检查员中看到),它看起来仍然很自然。

    现在我想给这个编码。

    令我惊讶的是,chest.localrotation.y的值与检查员显示的值完全不同。

    然后我查看了胸部变量并扩展了视图。 我只是看不到检查员显示的旋转值。

    在这种情况下,我该怎么办?

    我用这个来旋转骨头:

    Chest.LookAt(ChestLookTarget.position); 
    Chest.rotation = Chest.rotation * Quaternion.Euler(Offset);
    

    谢谢您! enter image description here

    1 回复  |  直到 6 年前
        1
  •  1
  •   derHugo    6 年前

    不起作用的原因是:

    Quaternion 不是人类可读的值。

    四元数 allways是唯一的,但可以有多个(无限?)中的不同表示 Euler 空间!另一条路绕一圈 欧拉 表示Allways正好一个 四元数 价值。

    如果你看文件,它明确地说

    不要直接修改这个,除非你知道四元数。


    你在巡查员身上看到的是 localRotation 关于父母 Transform .

    最好说这是可能的 欧拉 导致 四元数 . 在调试中看到的内容 localEulerAngles 还有可能吗 欧拉 代表。统一通常在 本地用户 也只给你价值观 > 0 .


    不管怎样,箱子似乎只能绕着 Y 轴心,对吗?

    如果是这种情况,你可以简单地得到胸部的原始正向向量和目标之间的角度。这样更容易处理 Vector3 价值比 四元数 s);

    它似乎与中的用例相同 this post

    // get the target direction
    Vector3 targetDir = ChestLookTarget.position - Chest.position;
    
    // Reset any difference in the Y axis
    // since it would change the angle as well if there was a difference I the height
    // between the two objects
    targetDir.y = 0;
    
    // however you currently rotate
    // instead rotate only the Vector3 variable without applying it to the transform yet
    Vector3 newDir = Vector3.RotateTowards(Chest.forward, targetDir, RotationSpeed * Time.deltaTime, 0.0f);
    
    // Compare the target direction to the parents forward vector
    float newAngle = Vector3.Angle(Chest.parent.transform.forward, newDir);
    
    if (newAngle > MaxRotationAngle)
    {
        // What should happen if angle gets bigger?
        return;
    }
    
    // If angle still okey set the new direction
    Chest.rotation = Quaternion.LookRotation(newDir);