gpt4 book ai didi

Quaternion.Lerp rotate too soon(四元数.Lerp轮换太快)

转载 作者:bug小助手 更新时间:2023-10-25 21:45:19 26 4
gpt4 key购买 nike



i use this code to rotate my avatar to targetPostion, but the problem is it alway rotate too soon & faster then the duration.

我使用这个代码将我的化身旋转到Target Postion,但问题是它总是旋转得太快&比持续时间快。


any ideas?

有什么好主意吗?


IEnumerator MoveToPosition(GameObject avatar, Vector3 targetPosition, float speed)
{
// Rotate towards the target
Vector3 direction = targetPosition - avatar.transform.position;
Quaternion toRotation = Quaternion.LookRotation(direction);

float STARmove = 0;
float duration = 1;

while (STARmove < duration)
{

STARmove += Time.deltaTime;


// Calculate rotation based on interpolation ratio
float t = Mathf.Clamp01(STARmove / duration);
avatar.transform.rotation = Quaternion.Lerp(avatar.transform.rotation, toRotation, t);

// Wait for a fixed time before next update
yield return new WaitForSeconds(Time.deltaTime);
}}

更多回答
优秀答案推荐

Interpolate between the start and end rotations, not between the current and end rotations.

在开始旋转和结束旋转之间进行插补,而不是在当前旋转和结束旋转之间进行插补。


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com