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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Third Person Camera Controller Doubt. Please Help!

Discussion in 'Scripting' started by Red_Kay, Dec 22, 2015.

  1. Red_Kay

    Red_Kay

    Joined:
    Aug 14, 2015
    Posts:
    94
    Yo!

    So my friend gave me script for my third person game, the script was for the camera. He gave me to go through it and learn something. But now I am stuck on statement and cant figure what is does exactly, he doesn't have time right so I posted my doubt here.

    3rd Person Camera Script:
    Code (CSharp):
    1.  
    2. y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f ;
    3.             y = ClampAngle(y, yMinLimit, yMaxLimit);
    4.  
    5.             yAim = y;
    I cant figure out why is he subtracting y (in the first line) with "Input.GetAxis("Mouse Y") * ySpeed * 0.02f". The initial values of y is 0f, ySpeed is 120.

    Thanks for your time! :)
     
  2. Svarr

    Svarr

    Joined:
    Dec 20, 2015
    Posts:
    22
    Have you tried the script? What happens when you move your mouse up or down?

    Does y get reset to 0f at the beginning of that method?

    I would guess that the subtraction reverses the camera movement in the up / down direction.

    What happens with yAim in the script?
     
    Red_Kay likes this.
  3. Red_Kay

    Red_Kay

    Joined:
    Aug 14, 2015
    Posts:
    94
    "y" is zero in the beginning but in "Start" he set it to 9
    I tried removing the "-" sign then it prevents the rotation of camera in x axis
    yAim is applied to camera rotation
     
  4. Svarr

    Svarr

    Joined:
    Dec 20, 2015
    Posts:
    22
    What happens if you replace the '-' with a '+'?

    y is zero in the beginning of what?

    Again, what happens with yAim in the script?