私はFPSプロジェクトを開始しました。私はプレイヤーとしてカプセルを持っています。空のGOは頭、カメラは頭の子オブジェクトです。ユニティでの垂直回転のクランプ
垂直軸では、y回転を-70(最小)と70(最大)に固定します。意外にも、値はクランプされません。
[SerializeField]
private Transform playerHead;
float inputHorizontal;
float inputVertical;
float sensitivity = 50;
float yMin = -70;
float yMax = 70;
Vector2 direction; // movement direction
Transform playerTransform;
void Start()
{
playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
}
private void Update()
{
inputHorizontal = Input.GetAxisRaw("Mouse X");
inputVertical = -Input.GetAxisRaw("Mouse Y"); // Inverted Input!
direction = new Vector2(
inputHorizontal * sensitivity * Time.deltaTime,
Mathf.Clamp(inputVertical * sensitivity * Time.deltaTime, yMin, yMax)); // The horizontal movement and the clamped vertical movement
playerTransform.Rotate(0, direction.x, 0);
playerHead.Rotate(direction.y, 0, 0);
}
値
direction.y
が、私はまだ360度で私の頭の周りに回すことができます。..