二、动画——11、播放动画的同时,改变某个骨骼部位的旋转

2022-02-13  本文已影响0人  GameObjectLgy
步骤一

动画层级的设置里勾选IK Pass


1644731851(1).png
使用OnAnimatorIK

这个API会每帧调用,如同update

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BoneRotationTest : MonoBehaviour
{
    public GameObject girl;
    private Animator anim;
    public Transform LookAtTargetTrans;
    void Start()
    {
        anim = girl.GetComponent<Animator>();
    }

    void OnAnimatorIK(int layerIndex)
    {
        //set bone local rotation
        //anim.SetBoneLocalRotation(HumanBodyBones.Head, Quaternion.Euler(0, 60, 0));
        ////get bone local rotation
        //Transform tran =  anim.GetBoneTransform(HumanBodyBones.Head);
        //Debug.Log(tran.rotation);

        float angle_Z = Vector3.Angle(LookAtTargetTrans.position - transform.position, transform.forward);
        Debug.Log(angle_Z);
        anim.SetBoneLocalRotation(HumanBodyBones.Head, Quaternion.Euler(0, 0, angle_Z));
    }
}
使用场景
上一篇 下一篇

猜你喜欢

热点阅读