I can’t solve the problem where you need to make a character turn with animation.
I have a Pivot that calculates the difference between the direction of the character and the direction of the target. If the target is more than 180 degrees, then quarantine is activated, the degree of rotation of the target is fixed, the animation of rotation by 180 is triggered, and the character is aligned on a flat point.
The problem is that if the direction of the target is slightly more or less than 180, then the character first turns 180, and then jerks to the desired angle.
Solution: You need to remove the turn in the animation itself so that the character turns in place and do it manually through the code.
But I can’t manage to make a complete and smooth turn to a certain angle in a certain time. I have already tried slerp and vlerp, but they do not turn all the way, but on the corner that they have time to turn during quarantine.
How can you smooth rotate a character to a certain angle in exactly 1 second?
PivotTarget:
Vector3 PivotTargetDirection = Vector3.RotateTowards(PivotTarget.transform.forward, PivotMove, 100, 0);
Turn:
IEnumerator Turn180()
{
canMove = false;
animator.SetBool("Walk", false);
animator.Play("Turn 180");
LastPivotTarget.transform.position = PivotTarget.transform.position;
LastPivotTarget.transform.rotation = PivotTarget.transform.rotation;
yield return new WaitForSeconds(1);
transform.rotation = LastPivotTarget.transform.rotation;
LastPivotTarget.transform.position = transform.position;
canMove = true;
}