Game Development Reference
In-Depth Information
(_vDirection * _forward);
if (_targetDirection != Vector3.zero) {
_moveDirection = Vector3.Slerp(_moveDirection,
_targetDirection, rotationSpeed * Time.deltaTime);
_moveDirection = _moveDirection.normalized;
} else {
_moveDirection = Vector3.zero;
}
}
Note
Vector3.Slerp()
is the function that we can use to interpolate between two
vectors spherically by the amount of time, and the return vector's magnitude will
be the difference between the magnitudes of the first vector and the second vector.
This function is usually used when we want to get the smooth rotation from one
vector to another vector in a fixed amount of time. You can see more details at
ht-
6. We are still in the
Update()
function. Next, we will calculate
_vertic-
alSpeed
and
_inAirTime
by checking whether our character is grounded.
Let's continue from the previous step and put the highlighted code as follows:
// Unity JavaScript user:
function Update () {
…
} else {
_moveDirection = Vector3.zero;
}
if (IsGrounded) {
_isJumping = false;
_verticalSpeed = 0.0f;
_inAirTime = 0.0f;
_inAirStartTime = Time.time;
} else {
_verticalSpeed -= GRAVITY * Time.deltaTime;
_inAirTime = Time.time - _inAirStartTime;
}