Game Development Reference
In-Depth Information
4. We compute the displacement vector for the player in this frame with
move-
mentDirection * movespeed
(remember that
movespeed
is smoothly inter-
polated and
moveDirection
is smoothly rotated toward
targetDirec-
ton
).
We scale displacement by
Time.delta
time (the amount of real time that
has elapsed since the last frame). We do this so that our calculation is time
dependent rather than frame rate dependent as shown in the following code:
Vector3 displacement =
moveDirection * moveSpeed *
Time.deltaTime;
5. Then, we move the character by invoking the
move
method on the
Char-
acterController
component of the player, passing the
displacement
vector as a parameter as follows:
this.GetComponent<CharacterController>()
.Move(displacement);
6. Finally, we assign the rotation of
MoveDirection
to the rotation of the trans-
form as follows:
transform.rotation =
Quaternion.LookRotation (moveDirection);