简体   繁体   English

Unity 3d 第一人称游戏开发表现怪异; 只能上下旋转

[英]Unity 3d first person game development acting weird; only can rotate up and down

im trying to make a first person game in unity, but I can only rotate up and down, and I was following a brackeys tutorial, and then I came across this error while programming it into my game.我试图制作一个统一的第一人称游戏,但我只能上下旋转,我正在学习 brackeys 教程,然后我在将它编程到我的游戏中时遇到了这个错误。

using UnityEngine;



public class NewBehaviourScript : MonoBehaviour
{

    public float mouseSensitivity = 100f;

    public Transform PlayerBody;

    float xRotation = 0f;

    // Start is called before the first frame update
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        PlayerBody.Rotate(Vector3.up * mouseX);
    }
} 

Did you try looking up the documentation?您是否尝试查找文档?

You are only rotating on the Z axis.您仅在 Z 轴上旋转。

transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);

Also, why are you assigning the transform's localRotation and using the Rotate() method at the same time?另外,为什么要同时分配变换的 localRotation 并使用 Rotate() 方法?

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

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