Game Development Reference
In-Depth Information
In line 50, we compute current camera rotation around its local x axis. This value is always
between 0 and 360, and it increases as the camera rotates clockwise. In other words, this
value will increase when the camera looks down as in part (c) in Illustration 22. In lines 54
through 56, we convert this value to an angle between 180 and -180 by converting angles
greater than 180 to negative angles (for example, 190 becomes -170 and so on). We store
this value in currentRotation to benefit from it later on in computing the limits of camera
rotation.
In lines 59 and 60, we compute the value of camera rotation for the current frame. This
value consists of -mouseDelta.y , verticalMouseSpeed , and Time.deltaTime, and it is com-
puted in a way similar to the one performed in a previous step to compute the cylinder ro-
tation. The exception here is the use of the negative value of mouse vertical displacement
-mouseDelta.y . The justification of that is: mouse movement upwards gives us a positive
value for mouseDelta.y , and we need to convert it to a camera rotation upwards, which is
in fact a counter-clockwise rotation around the local x axis of the camera. Therefore, the
negative value results in the counter-clockwise rotation we need, and vice-versa for camera
rotation downwards. After computing the angle we store it in the variable ang .
After computing rotation magnitude, what we need is to rotate the camera around its local
x axis by this magnitude. Here we have three possibilities: first possibility is that the mouse
did not move vertically, which results in zero value for ang . In that case we don't have to do
anything. The second possibility is that the mouse moved upwards, which means that ang
value is negative and will result in a camera rotation upwards. This is the case we check
in line 65, to make sure that the resulting angle after rotation ( ang + currentRotation ) is
greater than the minimum allowed value for camera rotation which is -maxVerticalAngle .
The third and last possibility is that the mouse moved downwards, which gives us positive
value for ang. In this case we have to make sure that ang + currentRotation is less than than
maxVerticalAngle . This is what we do in line 66. If one of these conditions applies, we rotate
the camera around its local x axis using ang value we have just computed. This rotation is
applied using transform. RotateAround() , which we call in line 67.
In lines 74 through 92 we scan the inputs of the four direction arrows and add the appro-
priate direction to the final speed. This input might be forward, backwards, right, or left.
The rest of lines have already been discussed in the platformer input system, so you can
Search WWH ::




Custom Search