I have a gameobject that needs to gradually rotate towards a target transform. I got it working but I wonder if this is the correct approach. It involves LookingAt the target object to capture the rotation, Then restoring the original rotation.
Quaternion backupRotation = this.sceneCameraGO.transform.rotation; //Backup the current rotation
this.sceneCameraGO.transform.LookAt(this.ekgSystem.transform); //Look at the target transform to capture the target rotation
targetRotation = this.sceneCameraGO.transform.rotation; //Capture the target rotation
this.sceneCameraGO.transform.rotation = backupRotation; //Restore the original rotation
Update()
{
//Gradually rotate towards the target rotation
this.sceneCameraGO.transform.rotation = Quaternion.RotateTowards(
this.sceneCameraGO.transform.rotation, targetRotation, 20.0f * Time.deltaTime);
}
I feel like there there is a better approach. I looked through the Quaternion API and don’t see any other approach that is obvious.
Thanks