Search Unity

how to determine when a lerp has been competed

Discussion in 'Scripting' started by spiralgear, Mar 4, 2008.

  1. spiralgear

    spiralgear

    Joined:
    Dec 13, 2007
    Posts:
    528
    so i have the character controller lerping towards an object when he is close to it. while hes lerping towards it i have the FPS walker scripts and some other things turned off


    the problem is that i cant figure out how to tell when he is DONE lerping so i can turn those scripts back on


    how can i figure out when hes done lerping?
     
  2. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Only by comparing the two values.

    Use Mathf.Approximately as you should never really try to compare 2 floats as rounding errors etc may make them never be equal using a == .
     
  3. spiralgear

    spiralgear

    Joined:
    Dec 13, 2007
    Posts:
    528
    so like
    Code (csharp):
    1.  
    2.  
    3.  
    4. if(transform.position   is about   target.position){
    5.  
    6.  
    7. //turn scripts back on
    8.  
    9.  
    10. }

    ?
     
  4. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Yes, if it is Vector3's you are comparing as there is no Approximately comparison for Vector3's.

    Or you could compare Vector3 elements for example.

    Code (csharp):
    1.  
    2. if (Mathf.Approximately(transform.position.x, target.position.x)) {
    3.    //Turn Scripts back On
    4. }
    5.  
    6.  
     
  5. spiralgear

    spiralgear

    Joined:
    Dec 13, 2007
    Posts:
    528
    cool thanks alot