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.

SmoothDamp is frame dependent even with Time.deltaTime

Discussion in 'Editor & General Support' started by Zuccotto, Jun 26, 2022.

  1. Zuccotto

    Zuccotto

    Joined:
    Jun 10, 2022
    Posts:
    1
    I am making my first 2D game and every movement (except for projectiles) is made with Vector2.SmoothDamp.
    Here is for example my player movement:
    transform.position = Vector2.SmoothDamp(transform.position, movePoint, ref velocity, smoothTime * Time.deltaTime);

    Everything works fine with this method, except for when I build the game and try it on my phone.
    Now everything that uses SmoothDamp is slower, making the game unplayable.
    Should I just move every SmoothDamp in a Fixed Update or is there a quicker solution?
     
  2. villevli

    villevli

    Joined:
    Jan 19, 2016
    Posts:
    81
    I think you should not multiply the smoothTime parameter with deltaTime as according to the docs: https://docs.unity3d.com/ScriptReference/Vector2.SmoothDamp.html it is the time it will take to reach the target. Multiplying it by deltaTime you are making the time shorter when the FPS is higher.

    So make it a constant instead of multiplying by deltaTime.
     
    spiney199 likes this.