Unity3d 为什么IK控制器不存在于Inspector中的ThirdPersonController Animator组件中?

Unity3d 为什么IK控制器不存在于Inspector中的ThirdPersonController Animator组件中?,unity3d,unity5,Unity3d,Unity5,我试图按照unity文档中的说明在本页中如何使用反向运动学: 但是,当我为动画师选择控制器时,我没有IK Animator控制器 我现在尝试添加脚本。但是右手的手被折叠到另一边。它不像是拿着闪光灯:脚本连接到第三个personcontroller。我把手电筒拖到了lookObj的右边,我把手电筒拖到了Inspector里的脚本 但这只手似乎走错了方向 这是我现在使用的脚本IKControl: using UnityEngine; using System; using System.Coll

我试图按照unity文档中的说明在本页中如何使用反向运动学:

但是,当我为动画师选择控制器时,我没有IK Animator控制器

我现在尝试添加脚本。但是右手的手被折叠到另一边。它不像是拿着闪光灯:脚本连接到第三个personcontroller。我把手电筒拖到了lookObj的右边,我把手电筒拖到了Inspector里的脚本

但这只手似乎走错了方向

这是我现在使用的脚本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);
            }
        }
    }
}
使用UnityEngine;
使用制度;
使用系统集合;
[RequiredComponent(typeof(Animator))]
公共类控制:单一行为
{
受保护动画师;
公共布尔ikActive=假;
公共转换rightHandObj=null;
公共转换lookObj=null;
void Start()
{
animator=GetComponent();
}
//用于计算IK的回调
void OnAnimatorIK()
{
如果(动画师)
{
//如果IK处于活动状态,请直接将位置和旋转设置为目标。
如果(ikActive)
{
//如果已指定一个,则设置“环视”目标位置
if(lookObj!=null)
{
动画师。设置lookatweight(1);
animator.SetLookAtPosition(lookObj.position);
}
//设置右侧目标位置和旋转(如果已指定)
if(rightHandObj!=null)
{
动画师。设置位置权重(头像右侧,1);
动画师。设置旋转权重(头像右侧,1);
animator.SetIKPosition(虚拟角色右侧、右侧位置);
animator.SetIKRotation(虚拟角色右侧、右侧、旋转);
}
}
//如果IK未处于活动状态,请将手和头部的位置和旋转设置回原始位置
其他的
{
animator.SetIKPositionWeight(AvatarIKGoal.RightHand,0);
animator.SetIKRotationWeight(AvatarIKGoal.RightHand,0);
设置lookatweight(0);
}
}
}
}

将一个空的游戏对象添加到手电筒中,并瞄准它,而不是手电筒对象本身。点击play,然后摆弄空对象的位置,直到它达到您想要的位置。然后,只需将手电筒转换为预设,停止播放模式,并确保场景中的手电筒与预设匹配(如果需要,您可以使用“还原”即可)


现在它每次都会做你想做的事。你甚至可以有多个预设,其中空对象的位置不同,以允许手大或手小的角色令人信服地握住它。

你尝试过将脚本添加到
游戏对象中吗?@Hristo是的,我现在尝试过。但它还不能很好地工作,手的折叠方式不对,看起来不像拿着手电筒。我用我所做的和我正在使用的脚本更新了我的问题。当你玩的时候,手有什么不同吗?另外,您是否更改了手部的
变换