Game Development Reference
In-Depth Information
Now let's get into the discussion of the first person input system. After declaring some variables
we call the function transform.FindChild() in line 35. What does this function do is searching
for the object with the provided name. This search is performed among the children of the
current object only. In this case, we have passed the name Main Camera , which is the default
name of the camera in Unity. Since we have already added the camera as a child to the cyl-
inder, this function is going to find the camera and return it to be stored in camera variable.
We are going to deal with this variable later on.
In the first step in lines 43 through 47, we call the function transform.RotateAround(), and
its job is to rotate the object around a specific axis. Therefore, we provide a rotation axis
and an angle. As for the axis it is Vector3.up , which is the positive direction of the global
y axis that goes up. Since this is a vertical axis, the resulting rotation is going to be hori-
zontal towards left or right. The rotation angle is a product of three values: first value is
mouseDelta.x , which is the horizontal mouse displacement since the last frame. This value
is positive when the mouse moves from left to right, which results in clockwise rotation as
in part (b) in Illustration 22, and counter-clockwise rotation when the mouse moves in the
opposite direction. The second value, horizontalMouseSpeed , represents the rotation speed.
In most games, this value can be customized by the player in order to match the speed
of mouse movement he is used to. The last value is Time.deltaTime , we have been dealing
with this value for a while, since we usually need to compute the distance or angle from the
speed.
Search WWH ::




Custom Search