Search Unity

Sprite Jittery Move

Discussion in '2D' started by BZLC, Sep 23, 2018.

  1. BZLC

    BZLC

    Joined:
    Jan 6, 2018
    Posts:
    4
    Hi All,

    I just want to move unity placeholder sprite with Vector2.MoveTowards function. No collider or rigidbody attached to the gameobject. However it gets jittery at the edges while move. The sample video is from the mobile build (same as PC). Is it due to my script or something related to graphics, default settings etc? Thanks.



    Code (CSharp):
    1. public class move : MonoBehaviour {
    2.  
    3.     public Vector2 target = new Vector2(0, 7);
    4.    
    5.     void Start () {
    6.        
    7.     }
    8.    
    9.    
    10.     void FixedUpdate () {
    11.  
    12.         transform.position = Vector2.MoveTowards(new Vector2(transform.position.x, transform.position.y), target, 3 * Time.deltaTime);
    13.  
    14.     }
    15. }
     
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    Have you tried removing the "* Time.deltaTime" part? It shouldn't be necessary in a FixedUpdate.
     
  3. BrienKing

    BrienKing

    Joined:
    Oct 11, 2015
    Posts:
    35
    Check out this video:

     
  4. BZLC

    BZLC

    Joined:
    Jan 6, 2018
    Posts:
    4
    This can a broad topic with many solutions available. Setting the "Application.targetFrameRate" by 60 instead of default 30 for mobile seems the least complicated solution for now.

    Thanks all.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    For the smoothest motion you should be doing the above Transform change in "Update" (per-frame) rather than "FixedUpdate". Also, "FixedUpdate" can be called multiple times per-frame in many cases resulting in you seeing it move several steps in a single frame (not necessarily the reason you get jitter here).
     
    terrareef27 likes this.