如何解决有什么方法可以缓慢平滑地更改Animator IK SetLookAtWeight?
using UnityEngine;
using System;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class IKControl : MonoBehaviour
{
protected Animator animator;
public bool ikActive = false;
public Transform headObj = null;
public Transform lookObj = null;
private bool changeWeight = false;
private float t = 0;
private float value = 0;
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)
{
changeWeight = false;
// Set the look target position,if one has been assigned
if (lookObj != null)
{
animator.SetLookAtWeight(1,1,1);
animator.SetLookAtPosition(lookObj.position);
}
}
//if the IK is not active,set the position and rotation of the hand and head back to the original position
else
{
changeWeight = true;
}
}
}
private void Update()
{
if(changeWeight == true)
{
t += Time.deltaTime / 5f;
value = Mathf.Lerp(1f,0f,t);
animator.SetLookAtWeight(value);
}
}
}
我正在尝试使用一个标志,并在Update中缓慢地更改该值,因此SetLookAtWeight在这种情况下仅需5秒钟即可进行测试。
但是SetLookAtWeight值就像从1跳到0,并且没有从1慢慢变到0。 当我运行游戏并将bool标志ikActive设置为false时,玩家的头会直接从注视模式立即更改为空闲模式。
我希望它缓慢地变为空闲模式。
解决方法
您永远不会重置t
的值。在玩了5秒钟后,它将大于1,因此Lerp将始终返回最大值。
尝试将此行添加到if (ikActive)
块的顶部
t = 0f;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。