Search Unity

Lerp without easing?

Discussion in 'Scripting' started by cmh322, Feb 25, 2010.

  1. cmh322

    cmh322

    Joined:
    Apr 3, 2009
    Posts:
    70
    Is there a scripting method that acts like Vector3.Lerp that will help me move an object from one position to another without the "easing in" effect?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vector3.Lerp has no easing, unless you specifically add it in somehow. It's just linear.

    --Eric
     
  3. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Vector3.Lerp is the right command, you just have to use it differently. Here's an example *untested*.

    Code (csharp):
    1. var targetPoint = Vector3.one;
    2. var duration = 0.3;
    3.  
    4. function Start ()
    5. {
    6.    var startPos = transform.position;
    7.    var startTime = Time.time;
    8.    while (Time.time - startTime < duration)
    9.    {
    10.       var amount = (Time.time - startTime) / duration;
    11.       transform.position = Vector3.Lerp (startPos, targetPoint, amount);
    12.       yield;
    13.    }
    14.    transform.position = targetPoint;
    15. }