protected virtual void CalculateNextRotation(float slowdown, out Quaternion nextRotation)
{
if (lastDeltaTime > 0.00001f)
{
Vector2 desiredRotationDirection;
if (rvoController != null && rvoController.enabled)
{
// When using local avoidance, use the actual velocity we are moving with if that velocity
// is high enough, otherwise fall back to the velocity that we want to move with (velocity2D).
// The local avoidance velocity can be very jittery when the character is close to standing still
// as it constantly makes small corrections. We do not want the rotation of the character to be jittery.
var actualVelocity = lastDeltaPosition / lastDeltaTime;
desiredRotationDirection = Vector2.Lerp(velocity2D, actualVelocity, 4 * actualVelocity.magnitude / (maxSpeed + 0.0001f));
}
else
{
desiredRotationDirection = velocity2D;
}
// Rotate towards the direction we are moving in.
// Don't rotate when we are very close to the target.
var currentRotationSpeed = rotationSpeed * Mathf.Max(0, (slowdown - 0.3f) / 0.7f);
nextRotation = SimulateRotationTowards(desiredRotationDirection, currentRotationSpeed * lastDeltaTime);
}
else
{
// TODO: simulatedRotation
nextRotation = rotation;
}
}