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. Dismiss Notice

Lerp is slightly jittery

Discussion in 'Editor & General Support' started by Jelmer123, Jun 1, 2021.

  1. Jelmer123

    Jelmer123

    Joined:
    Feb 11, 2019
    Posts:
    237
    Code (CSharp):
    1. public class TestingLerp : MonoBehaviour
    2. {
    3.     public Transform pos1;
    4.     public Transform pos2;
    5.     public float seconds;
    6.     float time;
    7.  
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.         time = Time.time;
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.         time +=Time.deltaTime;
    18.         transform.position = Vector3.Lerp(pos1.position, pos2.position, time/ seconds);
    19.     }
    20. }
    21.  
    Doing some Lerp testing. With seconds = 10f; and running 70FPS, I can still visually see that the LERP jitters a bit. How come? This code should be fine as long for the first 10 seconds?
     
  2. Arberk

    Arberk

    Joined:
    Feb 3, 2014
    Posts:
    5
  3. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    Why are you setting your timer to Time.time instead of 0 on Start?
     
    b4gn0 likes this.
  4. Jelmer123

    Jelmer123

    Joined:
    Feb 11, 2019
    Posts:
    237
    Yeah it doesn't make sense here.