【问题标题】:Why the IK controller is not exist in the ThirdPersonController Animator component in the Inspector?为什么 Inspector 中的 ThirdPersonController Animator 组件中不存在 IK 控制器?
【发布时间】:2017-07-25 06:17:54
【问题描述】:

我正在尝试按照统一文档中的说明如何使用此页面中的反向运动学:

Inverse Kinematics

但是当我为 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 吗?

标签: unity3d unity5


【解决方案1】:

将一个空的游戏对象添加到手电筒中,并以它而不是手电筒对象本身为目标。点击播放,然后摆弄空对象的位置,直到它位于您想要的位置。然后只需将手电筒变成预制件,停止播放模式并确保场景中的手电筒与预制件匹配(如果需要,您可以使用 revert 来执行此操作)。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-16
    • 2016-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多