Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Need a litlle help on a Lerp[RESOLVED]

Discussion in 'Scripting' started by Yearl, Sep 2, 2015.

  1. Yearl

    Yearl

    Joined:
    Jun 26, 2015
    Posts:
    33
    Hi everyone !

    I'm lerping an object A to B, ok that workd, pretty easy indeed.

    But I want more specific lerp with movin on axisY in the lerp:

    At A my objectY is set at 0, same for B, and I want while lerping object A upping on Yaxis and downing on B like a beatiful curve .

    Thanks !

    Image ref.
    http://postimg.org/image/85sgpthc1/
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,384
    You can make an Animation curve for the Y and sample it into the position each frame.
     
  3. Yearl

    Yearl

    Joined:
    Jun 26, 2015
    Posts:
    33
    Can be a way yes thanks, no other way with scripting ?
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    Plenty of ways with scripting - in fact, LaneFox's suggestion does involve scripting, I believe you've misinterpreted it. He's not saying make an animation; he's suggesting you create a variable of type AnimationCurve, and in the course of your loop, take a sample of the value at a given "time" value. AnimationCurves are useful for far more than just animation.

    Check out the AnimationCurve class in the manual for more info.
     
  5. Yearl

    Yearl

    Joined:
    Jun 26, 2015
    Posts:
    33
    Ah yes misinterpreted it ...
    Ok now I see what you mean, but another question, how can I the "given time value" while my lerp ?
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    Something like:

    Code (csharp):
    1.  
    2. public AnimationCurve someCurve; //you can edit this is the inspector
    3. void Update() {
    4. Vector3 lerpedPosition = Vector3.Lerp(a, b, someTimeValue);
    5. float heightFromCurve = someCurve.Evaluate(someTimeValue);
    6. transform.position = lerpedPosition + Vector3.up * heightFromCurve;
    7. }
     
  7. Yearl

    Yearl

    Joined:
    Jun 26, 2015
    Posts:
    33
    Sorry I don't get it ... I modify my lerp with yours, in "someTimeValue" I set Time.deltaTime*10f, but my object up, and up, and up again to infinity and never down.
    My curve it's like draw it above ... I don't understand.

    EDIT;
    Get finally a way ! I search for lerps exemple on Goo and discover that my lerps wasn't good constructed !
    Thanks at all, bye !
     
    Last edited: Sep 3, 2015