1

如您所见,手只是奇怪地放在角色面前。righthandhold 和 lefthandhold 是游戏对象的手应该继续的位置。

左边的截图是播放模式,中间的截图不是,所以没有IK。 截图 源代码(改编自一个统一的例子):

void OnAnimatorIK(int layerIndex) {
    float aim = 1f;

    if (layerIndex == 0) {
        if (player != null) {
            Vector3 target = player.transform.GetChild(0).position + Vector3.up;

            animator.SetLookAtPosition(target);
            animator.SetLookAtWeight(aim, 0.5f, 0.5f, 0.0f, 0.5f);

        }
    }

    if (layerIndex == 1) {
        if (leftHandOnGunPosition != null) {
            animator.SetIKPosition(AvatarIKGoal.LeftHand, leftHandOnGunPosition.transform.position);
            animator.SetIKRotation(AvatarIKGoal.LeftHand, leftHandOnGunPosition.transform.rotation);
            animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, aim);
            animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, aim);
        }

        if (rightHandOnGunPosition != null) {
            animator.SetIKPosition(AvatarIKGoal.RightHand, rightHandOnGunPosition.transform.position);
            animator.SetIKRotation(AvatarIKGoal.RightHand, rightHandOnGunPosition.transform.rotation);
            animator.SetIKPositionWeight(AvatarIKGoal.RightHand, aim);
            animator.SetIKRotationWeight(AvatarIKGoal.RightHand, aim);
        }
    }
}

谁能告诉我我做错了什么?

更新:我刚刚注意到右手比左手更靠前。就像枪上的位置一样。为了进行测试,我将目标位置换成了手,然后左手在右手的前面。所以它肯定会尝试将手移动到正确的位置......只是没有到达那里。

update2:我还尝试关闭查看内容(if (layerIndex == 0) 中的所有内容),以确保不会搞砸任何事情。没有任何区别,除了不再看球员。

4

1 回答 1

1

好吧,似乎问题是当我添加模型时,它与它所在的 navmeshagent 相比太高了。所以我在 navmeshagent 和模型之间制作了一个子游戏对象,并将它的 ay 设为 -1。

我能够通过添加+ Vector3.up到 IK 位置来临时修复 IK。

正确的解决方案是使用 y -1 删除中间子项,然后将 navmeshagent 中的基本偏移量从 1 更改为 0。

于 2016-12-22T12:10:30.640 回答