Game Development Reference
In-Depth Information
Illustration 19:
Binding a game object from the scene with a variable in a script
In addition to
playerCharacter
variable, we have defined four variables to shape the frame
in which the player character can move without moving the camera. These variables are
named after positions relative to the camera. We have therefore
maxDistanceRight
and
maxDistanceLeft
to define maximum allowed distances on the x axis. So if the character is
to the right of the camera, and the horizontal distance between the character and the camera
on x axis is greater than
maxDistanceRight
, the camera will move right in order to prevent
this distance from exceeding the defined limit. The same thing applies to
maxDistanceUp
and
maxDistanceDown
on the y axis. If we draw these limits as straight lines, they form a
rectangle around the player character as shown in Illustration 20.