- Home /
Question by
pikachuk · Oct 12, 2017 at 03:35 PM ·
c#scripting problemcamera rotatetransform.rotation
What is wrong in my camera rotator script ?
Hello, i'm currently writing a script for a custom third person camera and i've a problem with the script of the rotator, i tried a lot of things, but it never works properly, i want to lock the X rotation to specific limits in order to avoid the camera to go to the negative axis and messing up everything but i can't make it work properly
private void Update()
{
current = transform.localRotation;
}
// Update is called once per frame
void FixedUpdate () {
Quaternion changerotation = current;
changerotation.x += Quaternion.Euler( MouseY,0,0).x;
changerotation.y += Quaternion.Euler(0, MouseX,0).y;
transform.localRotation = changerotation;
transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, 0);
if (transform.eulerAngles.x > MaxX.x)
{
transform.eulerAngles = new Vector3(MaxX.x, transform.eulerAngles.y, 0);
}
if (transform.eulerAngles.x < MinX.x)
{
transform.eulerAngles = new Vector3(MinX.x, transform.eulerAngles.y, 0);
}
}
what could be the problem ? the camera, when this script is enabled and i move the mouse does weird rotations and can't rotate properly
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612140846im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problems with Gyroscope VR Car Game 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Confining Mouse Look on X axis 0 Answers
Restricting movement with Mathf.Clamp 4 Answers