不能统一地看侧面
我想制作FPS游戏。要创建第一人称观众,我遵循本教程 youtube
而且我可以成功地抬头或向下看,但看上去侧面。
这是代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mouselook : MonoBehaviour
{
float mousesenitivevity = 100f;
public Transform player_eyes;
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") * mousesenitivevity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mousesenitivevity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
player_eyes.Rotate(Vector3.up * mouseX);
}
}
我真的不知道错误发生在哪里,但我注意到了一些事情:
如果您评论行transform.localrotation.localrotation = quaternion.euler(xrotation,0f,0f,0f); << /code>然后,玩家可以向侧面看,但不能上下看,如果您输入播放器,玩家可以上下查找,但不能侧面。
这是Unity编辑器屏幕截图以获取更多详细信息: 编辑器image
I want to make a fps game. To create first person viewer I followed this tutorial youtube
I followed everything that he told to do and I could successfully look up or down but could not look sideways.
Here`s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mouselook : MonoBehaviour
{
float mousesenitivevity = 100f;
public Transform player_eyes;
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") * mousesenitivevity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mousesenitivevity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
player_eyes.Rotate(Vector3.up * mouseX);
}
}
I really do not know where the error is occurring but here are a few things I noticed:
If you comment out the line transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
then the player can look sideways but not up and down and if you uncomment it the player can look up and down but not sideways.
Here is the unity editor screenshots for more details:
Editor image
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了,我错误地将脚本放在播放器上,而不是相机上。
Solved, I put the script on the player instead of the camera by mistake.