Here I want to share how I smoothly turn character with Slerp.
Code: Select all
if (m_pCharacterController->IsWalking())//Third person camera, character turn when he moves.
{
//Get the face direction the character's supposed to face
Vec2 faceDir = m_pCharacterController->GetVelocity().GetNormalized();
//Convert face direction to Yaw Pitch Roll
Ang3 ypr;
ypr.x = -atan2(faceDir.x, faceDir.y);
ypr.y = 0;
ypr.z = 0;
// Set the rotation of character use Slerp
m_pEntity->SetRotation(
Quat::CreateSlerp(m_pEntity->GetRotation(), //Current rotation
Quat(CCamera::CreateOrientationYPR(ypr)),//Target rotation
frameTime * ROTATE_SPEED)//Rotate speed multiplies with frametime to make sure frame time independent
);
}
