学習練習として、私の "Player" GameObject(私のカメラの親である)に付けられたMouseLookAroundスクリプトを書いています。マウスの見た目がちらつくのはなぜですか?
using UnityEngine;
using System;
public class MouseLook : MonoBehaviour {
[Flags]
public enum RotationAxes
{
None,
LeftAndRight,
UpAndDown,
Both = LeftAndRight + UpAndDown
}
public RotationAxes axes = RotationAxes.Both;
public float horizontalSensitivity = 9f;
public float verticalSensitivity = 9f;
public float verticalMinimum = -45f;
public float verticalMaximum = 45f;
void OnGUI()
{
GUI.TextArea(new Rect(0, 0, 100, 20), "" + transform.localEulerAngles.x);
}
// Update is called once per frame
void Update() {
if ((axes & RotationAxes.LeftAndRight) != 0)
{
float yaw = Input.GetAxis("Mouse X") * horizontalSensitivity;
transform.Rotate(0, yaw, 0);
}
if ((axes & RotationAxes.UpAndDown) != 0)
{
float yaw = transform.localEulerAngles.y;
float pitch = -Input.GetAxis("Mouse Y") * verticalSensitivity;
//pitch = Mathf.Clamp(pitch, verticalMinimum, verticalMaximum);
pitch += transform.localEulerAngles.x;
transform.localEulerAngles = new Vector3(pitch, yaw, 0);
}
}
}
私はこのプロジェクトを実行して、アップ/ダウン私のマウスを移動すると、私は角度見下ろしたときに見上げたときに90に制限されて、そして私の角度がMathf.Clampがあるにもかかわらず(270に制限されていることに気付きますコメントアウト)。
さらに、ユニティがこれらの角度をクランプすると、ある程度のばらつきがあります。だから、私の視野角(ピッチ)がすでに90で、私のマウスをカメラの下に動かすと、89.98のようなものに変わり、場面全体がジャンプします。
誰かが私の範囲を制限している理由を説明してください。なぜこの吃音が発生するのですか?
これは、変換の回転が数学的に定義されているためです。例えば。あなたが南極にいるなら、あなたは "南"に行きます、どちらの方向ですか? – Glurth