【发布时间】:2017-07-25 06:17:54
【问题描述】:
我正在尝试按照统一文档中的说明如何使用此页面中的反向运动学:
但是当我为 Animator 选择 Controller 时,我没有 IK Animator Controller。
我现在尝试添加脚本。但右手的那只手是折叠到另一边的。它不像是拿着闪光灯:脚本附加到 ThirdPersonController。然后我将 Inspector 中的脚本拖到 rightHandObj EthanRightHand 和 lookObj 我拖到了手电筒。
但是手好像走错路了。
这是我现在使用的 IKControl 脚本:
using UnityEngine;
using System;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class IKControl : MonoBehaviour
{
protected Animator animator;
public bool ikActive = false;
public Transform rightHandObj = null;
public Transform lookObj = null;
void Start()
{
animator = GetComponent<Animator>();
}
//a callback for calculating IK
void OnAnimatorIK()
{
if (animator)
{
//if the IK is active, set the position and rotation directly to the goal.
if (ikActive)
{
// Set the look target position, if one has been assigned
if (lookObj != null)
{
animator.SetLookAtWeight(1);
animator.SetLookAtPosition(lookObj.position);
}
// Set the right hand target position and rotation, if one has been assigned
if (rightHandObj != null)
{
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1);
animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 1);
animator.SetIKPosition(AvatarIKGoal.RightHand, rightHandObj.position);
animator.SetIKRotation(AvatarIKGoal.RightHand, rightHandObj.rotation);
}
}
//if the IK is not active, set the position and rotation of the hand and head back to the original position
else
{
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 0);
animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 0);
animator.SetLookAtWeight(0);
}
}
}
}
【问题讨论】:
-
您是否尝试将脚本添加到
GameObject? -
@Hristo 是的,我现在试过了。但它还不能很好地工作,手折叠的方式错误,看起来不像是拿着手电筒。我用我所做的和正在使用的脚本更新了我的问题。
-
而你玩的时候手牌有什么区别吗?你也改变了手牌的
Transform吗?