【问题标题】:How do I rotate around a certain point but stop at a certain angle?如何围绕某个点旋转但停在某个角度?
【发布时间】:2020-05-31 01:48:07
【问题描述】:

我正在尝试围绕一个对象旋转相机,但当角度在 y 轴上达到 90 度时停止。

我找到了诸如“RotateTowards”之类的选项:https://docs.unity3d.com/ScriptReference/Quaternion.RotateTowards.html,以及诸如“RotateAround”之类的选项:https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html,但我正在尝试找到一种将两者结合起来的方法。

我尝试过但没有成功的代码:

void Update()
{
    if (cameraChange && transform.rotation.y != 90)
    {
        // transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0, 90f, 0), Time.deltaTime * speed);
           transform.rotation.RotateAround(player.transform.position, new Vector3(0, 1, 0), Time.deltaTime * speed);

    }
}

void GameOver()
{
    cameraChange = true;
    transform.LookAt(player.transform);
}

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    您遇到的问题是transform.rotation 返回一个quaternion,四元数的y 分量与y 轴不对应,实际上,建议您不要直接在除非你真的非常熟悉四元数。

    试试:

    transform.rotation.eulerAngles.y != 90 // this will correspond to the y-axis
    

    假设您的代码执行轮换工作,这应该可以解决您的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-11
      • 1970-01-01
      • 2022-09-26
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      相关资源
      最近更新 更多