如您所见,手只是奇怪地放在角色面前。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) 中的所有内容),以确保不会搞砸任何事情。没有任何区别,除了不再看球员。