【问题标题】:How to freez Y rotation in unity transform.LookAt()?如何在统一 transform.LookAt() 中冻结 Y 旋转?
【发布时间】:2021-06-10 19:00:22
【问题描述】:
using UnityEngine;



public class FollowPlayer : MonoBehaviour
{
    public Transform target;

    private void Update()
    {
        transform.LookAt(target);
    }
}

我需要删除 LookAt 中的 Y 旋转,帮帮我!

(我添加了一些信息,因为堆栈溢出需要我提供更多信息)

【问题讨论】:

  • 我很笨,我从这个链接中什么都不懂......请给我写完整的代码,我很笨
  • 您不想绕 Y 轴旋转?或者您不想考虑 Y 轴上的位置差异?

标签: c# unity3d


【解决方案1】:

我猜你的意思是将 y 轴归零。

在这种情况下,调用 LookAt 后,您想重置 y 轴

你的

private void Update()
{
    transform.LookAt(target);
    //reset the y axis here.
}

已修复

private void Update()
{
    transform.LookAt(target);
    transform.rotation.y = 0;
    //make sure to call that after LookAt, otherwise it will override the other line
}

我建议你看一些教程而不是被喂代码。

【讨论】:

    猜你喜欢
    • 2021-09-27
    • 2017-08-18
    • 2022-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多