Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Lock viewing angles

Discussion in 'Scripting' started by ChronicalGamingDevelopment, Feb 26, 2021.

  1. ChronicalGamingDevelopment

    ChronicalGamingDevelopment

    Joined:
    Feb 26, 2021
    Posts:
    3
    Hey guys!
    I have a problem with my camera controller: the character kan look 360° Around and even inside of himself! how o i lock these variables to how far he can look up and down?
    Code (CSharp):
    1. public float dpi = 100.0f;
    2. public GameObject Cam;
    3.  
    4.     void Update()
    5.  
    6.     {
    7.         var y = Input.GetAxis("Mouse Y") * Time.deltaTime * -dpi;
    8.        
    9.         Cam.transform.Rotate(y, 0, 0);
    I would be happy if anyone would help me.
     
  2. Putcho

    Putcho

    Joined:
    Jun 1, 2013
    Posts:
    246
    try mathf.Clamp
    https://docs.unity3d.com/ScriptReference/Mathf.Clamp.html
     
  3. ChronicalGamingDevelopment

    ChronicalGamingDevelopment

    Joined:
    Feb 26, 2021
    Posts:
    3
    Putcho likes this.
  4. Putcho

    Putcho

    Joined:
    Jun 1, 2013
    Posts:
    246
    y = mathf.Clamp(y, min, max);