Hi, I have been trying to fix it all day long, I searched in everywhere, but nothing worked
My problem is that I have my player with a cam attached to it and the rotations are fine, but want to limit the rotation of the x axis in the camera between -15 and 15, do you know how can I do it? D:
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
private Animator anim;
private CharacterController controller;
public float speed = 6.0f;
public float turnSpeed = 60.0f;
private Vector3 moveDirection = Vector3.zero;
public float gravity = 20.0f;
public Transform camTransform;
//(…)
//Camera
public float Y_ANGLE_MIN = -15.0f;
public float Y_ANGLE_MAX = 15.0f;
private float turnx = 0.0f;
private float turnyc = 0.0f;
void Update (){
//Animations
(...)
//Moving
(...)
//Rotations
turnx = Input.GetAxis ("Mouse X");
turnyc = Input.GetAxis ("Mouse Y");
transform.Rotate(0, turnx * turnSpeed * Time.deltaTime, 0);
controller.Move(moveDirection * Time.deltaTime);
moveDirection.y -= gravity * Time.deltaTime;
camTransform.transform.Rotate (turnyc * turnSpeed * Time.deltaTime * -1, 0, 0);
}
}