Here I want to share how I smoothly turn character with Slerp.
If you think this code can be optimized even more, please post it here. Thanks
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
ypr.x = -atan2(faceDir.x, faceDir.y);
ypr.y = 0;
ypr.z = 0;
// Set the rotation of character use Slerp
Quat::CreateSlerp(m_pEntity->GetRotation(), //Current rotation
frameTime * ROTATE_SPEED)//Rotate speed multiplies with frametime to make sure frame time independent