Weird clamping bug?

33 views Asked by At

Whenever cameraPivotPoint's rotation on the x axis hits a negative number, it sets it to the highest number in the clamp no matter what you set it to, I have no idea what's going on and don't know what to do about it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerCntroller : MonoBehaviour
{

    [Header("GameObjects")]
    [SerializeField] GameObject mainCamera;
    [SerializeField] GameObject cameraPivotPoint;
    

    [Header("Input")]
    [SerializeField] PlayerInput input;
    
    [Header("Floats")]

    [Header("Vector 3s")]
    [SerializeField] Vector3 cameraOffset;

    [Header("Vector 2s")]
    [SerializeField] Vector2 mouse;

    // Start is called before the first frame update
    void Start()
    {
        mainCamera.transform.position = cameraPivotPoint.transform.position + cameraOffset;
    }

    // Update is called once per frame
    void Update()
    {
        Camera();
    }

    void Camera()
    {
        mouse = input.actions["Look Around"].ReadValue<Vector2>();

        cameraPivotPoint.transform.rotation *= Quaternion.AngleAxis(mouse.y, Vector3.right); // Rotate the camera up and down
        cameraPivotPoint.transform.rotation *= Quaternion.AngleAxis(mouse.x, Vector3.up); // Rotate the camera left and right
        cameraPivotPoint.transform.position = this.transform.position;
        cameraPivotPoint.transform.eulerAngles = new Vector3(Mathf.Clamp(cameraPivotPoint.transform.eulerAngles.x, -70f, 70f), cameraPivotPoint.transform.eulerAngles.y, 0);
    }
}

Thank you!

I've already messed around with the max of the clamp, and the problem persists even if you set the max to a negative. ¯_(ツ)_/¯

0

There are 0 answers