Game Development Reference
In-Depth Information
In a similar implementation to PhysicsCarDriver , we declare a number of flag variables
that describe the current control state of the character. Each one of these variables has
a corresponding function that can be called to set its value. For example, calling
WalkForward() sets the value of walkForward flag to true , as well as setting the value of
walkBackwards flag to false. The same rule applies to all other flags. One interesting
function is Turn() , which does not deal with any flags, but simple takes a value that re-
presents a rotation degree, and rotates the capsule around the y axis by the provided degree.
The last (and most important) function we need is FixedUpdate() , which applies the state of
control flags to the rigid body of the character. The first step is in line 56, in which we
measure the current velocity of the character and store it in velocity variable. The next step
is to update the movement of the object on x and z axes based on the state of walking and
strafing flags. We assume that the character cannot direct itself while flying in the air (i.e.
during jumping), so we make sure it is either grounded or stuck somewhere with a vertic-
al velocity that is almost zero. This latter case can happen with non flat grounds and other
cases. For example, consider the case where the character stands over a small gap between
two boxes, like in Illustration 60. In this case OnGround() function will certainly return
false , because the ray will be cast down through the gab, and hence will pass more than
10 cm before hitting the ground. However, we still want the character to be able to move,
otherwise it is going to be stuck forever.
Search WWH ::




Custom Search