【问题标题】:How to change the plane that Vector3.Slerp rotates on?如何更改 Vector3.Slerp 旋转的平面?
【发布时间】:2022-01-11 02:14:54
【问题描述】:

就我对 Slerp 的理解而言,这就是我应该使用 Vector3.Slerp 函数的方式。我想从start 点发射一个球体到target 点并围绕middle 旋转。

using UnityEngine;

public class Projectile : MonoBehaviour
{
    public Vector3 start;
    public Vector3 target;
    public Vector3 middle;

    public float flyTime;
    float launchTime;

    void Start()
    {
        launchTime = Time.time;
    }

    void Update()
    {
        float percentage = (Time.time - launchTime) / flyTime;
        transform.position = Vector3.Slerp(start - middle, target - middle, percentage) + middle;
    }
}

问题是,对象将沿中间的上轴旋转,而不是像我在 YouTube 上看到的教程中看到的那样沿右轴旋转。

这是预期的轨迹:

这就是我的代码遵循的轨迹:

【问题讨论】:

标签: unity3d rotation


【解决方案1】:

按照 SLerp documentation 下面的示例,您必须稍微偏移 Y 轴上的旋转中心才能创建垂直弧线。

希望有所帮助;)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    相关资源
    最近更新 更多