Game Development Reference
In-Depth Information
Even this script is attached to the camera, it affects the character as well. At the beginning
we declare a few variables that will help us to control the camera (lines 7 through 24).
These variables control the speed of the horizontal rotation of the character and the vertical
movement of the camera, in addition to the limits of vertical camera rotation and the limits
of zooming in and out. Notice in lines 18 and 19 that the maximum and the minimum values
of zooming are both negative values, since the camera must always be behind the character.
According to the left-hand rule we use, positive direction of the z axis goes inside the screen.
In Start() function, specifically in line 36, we define the variable playerBody of type Trans-
form . We are going to use this variable to reference the character. The transform of the
character can be accessed through transform.parent , which returns the parent of the current
game object. Remember that we attach this script to the camera, which is a child of the char-
acter.
In lines 44 and 45 we convert the horizontal displacement of the mouse to a rotation of
playerBody around the y axis, in a way similar to what we have done in the first person
system. In lines 52 through 62 we declare the variable yDelta to compute the vertical mouse
displacement based on the value of invertYMovement . The value of invertYMovement de-
cides whether the displacement of the camera will match the direction of the vertical mouse
displacement or it will be in the opposite direction. After that we perform the vertical
movement of the camera in the world space, which takes place in line 62.
Search WWH ::




Custom Search