I don’t get how this could work

Updated on June 23, 2019 in Unity
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on June 21, 2019

 

So im reading a book called “Unity in action” and for the camara movement part (this is only to move up and down) there is this bit of code and it can be that im bad at maths or im missing something but if a -= b*c means a = a-(b*c) then if the mouse Y input is negative and the rotationX variable is already negative wouldn’t it result in a positive number? i mean -20 -= -0.5*10 would be *variable* = -20 -(-0.5 * 10) that would result in -20 + 5 right ? then why does the Y coordinate still go down when u get a negative Y input?

The piece of code is made bold btw.

else if (axes == RotationAxes.MouseY)
{
_rotationX -= Input.GetAxis(“Mouse Y”) * sensitivityVert;
_rotationX = Mathf.Clamp(_rotationX, minimumVert, maximumVert);

float rotationY = transform.localEulerAngles.y;

transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);
}

 

Sorry if this is confusing but im not the best at explaining things :/

  • Liked by
Reply
1 on June 21, 2019

Because in Unity, when you’re rotating to look down  you’re actually increasing the X-rotation.

90 is looking straight down, and -90 is straight up.

 

Now that we know this, lets look at the math again.

So you’re already at -20, that means looking up slightly,

and you’re moving the mouse down (-0.5) with some sensitivity mod (10), so -5

(-20 – -5 = -15), -15 is looking down more than -20 is.

 

and this should work backwards too, so lets do that again, but this time, were already looking down at 20

So, (20 – -5 = 25), 25 is looking down more that 20.

 

and this should work backwards AGAIN, like moving the mouse up.

(20 – +5 = 15), 15 is looking up more than 20.

on June 23, 2019

oooh ok i didnt know -90 was looking up :/ thx for the answer 😀

Show more replies
  • Liked by
Reply
Cancel