Can't cap camera x rotation
I can't figure out how to cap camera X rotation in my movement/camera rotation script. Here it is:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public Camera eyes;
CharacterController controller;
public float speed = 6.0f;
public float sensitivity;
float moveFB;
float moveLR;
float mouseX;
float mouseY;
void Start()
{
controller = GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
moveFB = Input.GetAxis("Vertical");
moveLR = Input.GetAxis("Horizontal");
mouseX = Input.GetAxis("Mouse X");
mouseY = Input.GetAxis("Mouse Y");
transform.Rotate(0,mouseX*sensitivity,0);
Vector3 movement = new Vector3(moveLR*speed*Time.deltaTime, 0, moveFB*speed*Time.deltaTime);
controller.Move(transform.rotation*movement);
eyes.transform.Rotate(-mouseY*sensitivity,0,0);
}
}
Comment
Your answer
Follow this Question
Related Questions
Let character moving towards it's facing? 0 Answers
Y Axis doesn't work with MouseLook 0 Answers
How to Rotate player on Y Axis using Mouse position, but also Clamp the rotation distance? 0 Answers
How can i make my player to follow my fingar 0 Answers
FPS camera mouse script - look around only when Mouse button is pressed down? 0 Answers