Hey @radhat , thanks for bringing this up. Yes, you are correct. I’ve used “10f * Time.deltaTime” for the interpolation ratio. if you increase that number to anything above 100 it will mitigate some of the rotation drift. Don’t know how big of an issue this would be in an actual game, as your target will move with you changing the Slerp values
I’ve also tested with just Quaternion.LookRotation() - and it also had some rotation drift when you are really close to the target
What was unclear from the unity Description of Slerp?
Spherically interpolates between quaternions a
and b
by ratio t
. The parameter t
is clamped to the range [0, 1].
Use this to create a rotation which smoothly interpolates between the first quaternion a
to the second quaternion b
, based on the value of the parameter t
. If the value of the parameter is close to 0, the output will be close to a
, if it is close to 1, the output will be close to b
.
protected void FaceTarget()
{
Quaternion currentRotation = stateMachine.transform.rotation;
if (stateMachine.Targeter.CurrentTarget==null) {return;}
Vector3 lookPos = stateMachine.Targeter.CurrentTarget.transform.position - stateMachine.transform.position;
lookPos.y = 0f;
stateMachine.transform.rotation = Quaternion.Slerp(currentRotation,Quaternion.LookRotation(lookPos),200f * Time.deltaTime );
}