Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Movement stutters every few seconds

Discussion in '2D' started by Techdesignimp, May 7, 2023.

  1. Techdesignimp

    Techdesignimp

    Joined:
    Feb 5, 2023
    Posts:
    1
    Hi, rencently I started developing a 2D runner for Android and I noticed a very strange thing, the objects in the background (everything except player) stutters every 1 second or so. It's obvious on Android and if you pay attention you can observe this even in the editor.
    I've tried everything I knew and researched and nothing worked. Please help!

    Code examples that I have tried:
    1) With Rigidbody2D, interpolation active and camera attached to the player
    Code (CSharp):
    1. Rigidbody2D r;
    2. float speed = 750f;
    3.  
    4. void Start () {
    5. r = this.GetComponent<Rigidbody2D>();
    6. }
    7.  
    8. void FixedUpdate(){
    9. r.velocity += Vector3.right * speed * Time.deltaTime;
    10.  
    2) Without Rigidbody and camera attached to the player

    Code (CSharp):
    1.  
    2. float speed = 7.5f;
    3.  
    4. void Update(){
    5. this.transform.position += Vector3.right * speed * Time.deltaTime;
    6.  
    I also use Application.targetFrameRate =60;
    And tried 30, 45 and other values but 60 worked best.

    In player settings I switched to IL2CPP and Incremental GC on and off. Nothing seems to work... if you need I can post a video with the issue.
     
  2. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    the player doesnt stutter because he is always dead center on the camera, maybe there is an issue with the player movement, try to make the camera static and make the player move around and see if the player stutters
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    Impossible to say but I'm also seeing the fact that you're accelerating at 750m/s. You need to keep velocities and thus forces at reasonable values. I'd dread to think how big the velocity would get above. I'm not saying this is the issue because there's little information but this isn't going to help.