- Home /
Question by
glogic1 · Jul 05, 2012 at 11:20 PM ·
cameraslerplookrotation
How to know when camera stops rotating using lookRotation
Im very new to unity and javascript so I shall be asking some pretty dumb questions here for awhile so bare with me :) I am writing a script to drop onto the camera and the camera rotates to look at what ever the target object is and when the camera is finished rotating to the object i want to change the followTarget var to false. But I can seem to figure a way of knowing when the camera is finished rotating correctly. . I have the below code in the LateUpdate function and it eventually hits the followTarget = false but it takes afew game loops after the camera has stopped rotating. Can anyone tell me the correct way to do this? Or explain why it takes a few update loops more then it should to hit the bool assignment?
var smoothRotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, smoothRotation, Time.deltaTime * damping);
print("smooth rotation " + smoothRotation);
if((transform.rotation == previousRotation) && (closeEnough == true)){
followTarget = false;
print("follow target" + followTarget);
}
previousRotation = transform.rotation;
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613073751im_/https://answers.unity.com/themes/thub/images/avi.jpg)