Vector3.Lerp()平滑效果异常,手部摇摆系统卡顿问题求助
Vector3.Lerp()平滑效果异常,手部摇摆系统卡顿问题求助
大家好,我正在开发一个手部摇摆系统,目前遇到了一个棘手的问题:当我使用Vector3.Lerp()来实现手部跟随目标的平滑移动时,效果非常糟糕,明显能感觉到卡顿和不流畅的抖动。
我已经试过两种插值方法——Vector3.Lerp()和Vector3.Slerp(),但两者的表现没有任何区别;同时我还把代码分别放到了Update()、FixedUpdate()甚至LateUpdate()中执行,情况也没有得到明显改善。
下面是我的代码细节:
精简版核心代码
Transform target; float smooth; void Update() { transform.position = Vector3.Lerp(transform.position, target.transform.position, smooth * Time.deltaTime); }
完整代码
using System.Collections; using System.Collections.Generic; using UnityEngine; public class HandSway : MonoBehaviour { public float smooth; public float swayMultiplier = 1f; public Vector3 handOffset; public Transform target; private void Update() { float x = Input.GetAxisRaw("Mouse X") * swayMultiplier; float y = Input.GetAxisRaw("Mouse Y") * swayMultiplier; Quaternion xRot = Quaternion.AngleAxis(-y, Vector3.right); Quaternion yRot = Quaternion.AngleAxis(x, Vector3.up); Quaternion rotation = xRot * yRot * target.rotation; transform.localRotation = Quaternion.Slerp(transform.localRotation, rotation, smooth * Time.deltaTime); transform.position = Vector3.Lerp(transform.position, target.transform.position, smooth * Time.deltaTime); } }
编辑器设置情况
- 脚本挂载在名为Hand的游戏对象上
- Inspector面板中,
target字段已绑定场景内的Hand Pos对象
有没有大佬能帮我看看问题出在哪,怎么才能让手部的跟随变得流畅自然呢?
备注:内容来源于stack exchange,提问作者Erfan_Games
相关产品推荐
相关产品推荐

