Vector3.Lerp in update, how stop?
Hi all. I have 1 camera in main menu scene, and this camera can move between tab menu (settings, credits etc.) Camera moved through Vector3.Lerp in update func. After the moving camera, it sticks. I can't move the camera even in the 'Scene creator'. I understand, Vector3.Lerp continue to be implemented. How i can stop this script after the camera move to EndPoint?
*** Code forcing move the camera:
void OnMouseDown() {
if(option){
if (!started_option) {
started_option = true; // Перемещение камеры в другую точку.
}
}
}
*** And this pushes camera:
void Update() {
if(started_option == true) {
camera1.transform.position = Vector3.Lerp (StartPoint.position, EndPoint.position, Time.deltaTime*10);
}
}
Thanks everyone for the tips!! GoodLuck with coding.
Answer by Cuttlas-U · Sep 25, 2017 at 10:23 AM
hi; u have to make the started_option to "False" when it finished; sadly in Lerp it wont finish in most time ; it means we cant check if the position is the same as end point so we stop it ; so u better use Vector3.MoveTowards instead of lerp; but if u want to continue using lerp u can check the distance between end point ;
like this :
void Update() {
if(started_option == true) {
camera1.transform.position = Vector3.Lerp (StartPoint.position, EndPoint.position, Time.deltaTime*10);
if ( Vector3.Distance(camera1.transform.position , EndPoint.Position) < 1)
started_option = false;
}
Very grateful!! I use u first variant, works great! But after i replace Vector3.Lerp > Vector3.$$anonymous$$oveTowards! Thx u again :)