【问题标题】:Camera: How to stop the player turn up and down on y-axis in unity?相机:如何阻止玩家在y轴上统一上下转动?
【发布时间】:2018-04-21 18:46:04
【问题描述】:

如何停止角色在 y 轴上的相机转动和倾斜?我的意思是我希望能够在不改变玩家位置的情况下向上和向下看。可以让它在 x 轴(左右)上转动。 代码如下:

using UnityEngine;
using System.Collections;

public class Actions : MonoBehaviour
{
        public float speedH = 2.0f;
        public float speedV = 2.0f;

        private float yaw = 0.0f;
        private float pitch = 2.0f;

        private void Update()
        {
            yaw += speedH * Input.GetAxis("Mouse X");
            pitch = Input.GetAxis("Mouse Y");

            pitch = Mathf.Clamp(pitch, -30f, 45f);

            transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);

        }
        private void Start()
        {
        }
}

【问题讨论】:

  • 这真的是您当前的代码吗?我认为这不会编译。你有两次Update 函数。如果您不想绕 x 轴旋转,则删除音高代码并将 x 轴替换为 0。
  • remove the pitch code and replace x axis with 0. 正如程序员所说。

标签: c# unity3d camera


【解决方案1】:

我会创建一个空的游戏对象并将相机作为其父级。然后我会使用脚本将 obj 移动到玩家的位置,然后根据鼠标输入轴旋转 obj。

【讨论】:

  • 是的,我这样做了,但是我的对象随着相机旋转,我想让它保持静止。例如,如果我向上看,我的对象会仰卧而不是站立。
  • 播放器对象或空对象。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-12
  • 1970-01-01
相关资源
最近更新 更多