- Home /
limiting camera rotation
Im working on something akin to a mirror. The script is supposed to ensure that as the player is moving, the cameras position changes at an angle like a real mirror. My problem is that at some points when the player is moving, the camera rotates backwards which is detrimental to my game. How do I effectively use clampf or limit the rotation in this situation.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Mirror_scripts : MonoBehaviour { public Transform MirrorCam1; public Transform MirrorCam2; public Transform PlayerCam;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
CalculateRotation ();
}
public void CalculateRotation()
{
Vector3 dir = (PlayerCam.position - transform.position).normalized;
Quaternion rot = Quaternion.LookRotation (dir);
rot.eulerAngles = transform.eulerAngles-rot.eulerAngles ;
//rot = Mathf.Clamp (rot, -60f, 60f);
MirrorCam1.localRotation = rot;
//MirrorCam1.transform.localEulerAngles=new Vector3(0,Mathf.Clamp(MirrorCam1.transform.localEulerAngles.y,-90f,90f),0);
MirrorCam2.localRotation = rot;
}
}
Your answer
Follow this Question
Related Questions
Controlling camera rotation limits. 1 Answer
Using Mathf.Clamp To Limit Camera Movement 0 Answers
Limit cameras near range ? 1 Answer
Multiple rotate with mouse 2 Answers
limit camera vertical rotation 1 Answer