简体   繁体   English

如何在统一变换中冻结 Y 旋转。 LookAt()?

[英]How to freez Y rotation in unity transform.LookAt()?

using UnityEngine;



public class FollowPlayer : MonoBehaviour
{
    public Transform target;

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

I need to delete Y rotation in LookAt, help me!我需要删除 LookAt 中的 Y 旋转,帮帮我!

(Im add some iformation cose STACKL OVERFLOW want some more information from me) (我添加了一些信息,因为 STACKL OVERFLOW 想从我这里得到更多信息)

im guessing what you're implying is zeroing out the y axis.我猜你的意思是将y轴归零。

in that case, after you call your LookAt, you want to reset the y axis在这种情况下,在您调用 LookAt 后,您想要重置 y 轴

YOURS你的

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

FIXED固定的

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

i'd recommend you watch a few tutorials instead of being fed code.我建议你看一些教程而不是被喂代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM