I want to rotate my player vehicle into the target object direction/side. Though the following image, I have tried to explain my point in a better way:
I want to rotate my below tank object towards another tank object so that it can point into that direction.
I have written this code for this purpose but it is not working:
IEnumerator DoRotationAtTargetDirection(Transform opponentPlayer)
{
Quaternion targetRotation = Quaternion.identity;
do
{
Debug.Log("do rotation");
Vector3 targetDirection = opponentPlayer.position - transform.position;
targetRotation = Quaternion.LookRotation(targetDirection);
Quaternion nextRotation = Quaternion.Lerp(transform.localRotation, targetRotation, Time.deltaTime);
transform.localRotation = nextRotation;
yield return null;
} while (Quaternion.Angle(transform.localRotation, targetRotation) < 0.01f);
}
I just want to smoothly rotate and stop towards a target object. Please share your suggestion regarding this.
