Hey, im working on a character movement script. I’ve got a problem with limiting my camera rotation. The script actually limites the rotation of the camera, but not exactly at the point i’d like to. Instead of stopping the camera at 0.3 (or -0.3), it does stop it at 0.3x (or -0.3x) which completly blocks the camera rotation. Any tips?
using UnityEngine;
using System.Collections;
public class Movements : MonoBehaviour
{
public float speed = 10.0F;
public float RotSpeed = 150.0F;
void Update()
{
// Getting axises
float forwardBackward = Input.GetAxis("Vertical") * speed * Time.deltaTime;
float leftRight = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
float RotLeftRight = Input.GetAxis("Mouse X") * RotSpeed * Time.deltaTime;
float RotUpDown = Input.GetAxis("Mouse Y") * RotSpeed * Time.deltaTime;
// Doing movements
transform.Translate(0, 0, forwardBackward);
transform.Translate(leftRight, 0, 0);
transform.Rotate (0, RotLeftRight, 0);
if(transform.rotation.x > -0.3 && transform.rotation.x < 0.3)
transform.Rotate(RotUpDown, 0, 0);
}
}