I have this code here and I was trying to make the rotation be clamped so it can’t rotate all the way around, but now its just rolling up to a certain point. So how do I get it to where it looks up and down and side to side only up to a certain point on each side.
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
public class CameraRotate : MonoBehaviour
{
public float speedH = 2.0f;
public float speedV = 2.0f;
private Camera maincamera;
private float yaw = 0.0f;
private float pitch = 0.0f;
private float rotationZ = 0f;
private float rotationX = 0f;
void Start()
{
maincamera = Camera.main;
}
void Update()
{
maincamera.transform.LookAt(transform);
float speed = 10.0f;
rotationX = CrossPlatformInputManager.GetAxis("Horizontal_2") * speed;
rotationZ = CrossPlatformInputManager.GetAxis("Vertical_2") * speed;
rotationX = Mathf.Clamp(rotationX, -90, 90);
rotationZ = Mathf.Clamp(rotationZ, -90, 90);
transform.localEulerAngles = new Vector3(rotationX, transform.localEulerAngles.y, rotationZ);
}
}