Question by
minwager · May 14, 2017 at 06:34 AM ·
cameracamera rotate
Can't limit First Person camera rotation?
Hello, I'm currently working on a character controller script and am trying to use the Mathf.Clamp function to limit the rotation of the camera on the Y axis, but it seems no matter what I enter for the limiting values, the camera is still able to rotate a full 360 degrees. Here's what I have.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
public float playerSpeed = 5.0f;
public float sensitivity = 2f;
public GameObject Eyes;
float rotX;
float rotY;
void Start ()
{
transform.position = new Vector3 (-11, 4, 3);
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update ()
{
transform.Translate (Vector3.right * Input.GetAxis("Horizontal") * playerSpeed * Time.deltaTime);
transform.Translate (Vector3.forward * Input.GetAxis ("Vertical") * playerSpeed * Time.deltaTime);
transform.Rotate (0, rotX, 0);
Eyes.transform.Rotate (-rotY, 0, 0);
rotX = Input.GetAxis ("Mouse X") * sensitivity * Time.timeScale;
rotY = Input.GetAxis ("Mouse Y") * sensitivity * Time.timeScale;
rotY = Mathf.Clamp (rotY, -60f, 60f);
}
}
Comment
Your answer
Follow this Question
Related Questions
Camera rotation problem 0 Answers
Why does my transform.lookat not work? 1 Answer
Fixed Camera rotate to follow player 2 Answers
How to make one movement direction be equal to diferent cameras? 2 Answers
3d camera not working as I want it to 0 Answers