Search Unity

Problem with smooth movement

Discussion in 'Web' started by patrickk2, Jan 15, 2021.

  1. patrickk2

    patrickk2

    Joined:
    Dec 8, 2019
    Posts:
    92
    Hello everyone!

    I am having a little trouble getting smooth movement for my GameObjects. I am currently testing with simple sriangle sprites and a gray background, so nothing too fancy.

    The triangle would move smoothly for a bit, but every now and then do a little jerk forward. Sometimes it is hardly noticable, and at other times it is. I want to eliminate the possibility that I am doing something obviously wrong, so I would really appreciate any tips or ideas, why this might be happening.

    Some more details about my test:
    • WebGL build
    • It is a 2D scene, I use Vector2 for all the movement code
    • The mouse click detection (for the new target position) as well as the movement itself happen in Update()
    • I use
      Vector2.MoveTowards(transform.position, target, speed * Time.deltaTime)
      to determine the new position for this frame
    I have also tried with
    Vector2.Lerp()
    , and what I found in a blog post: How to Lerp like a pro, but the problem remains (although harder to notice with Lerp).

    Any hints and pointers in the right direction would be greatly appreciated!

    Thanks in advance and best regards,
    Patrick
     
  2. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    In a small project with very few objects, there are not too many ways to get it wrong. If few objects run smoothly in a native windows/macOS app, it should run smooth on the web. Are you running a Release build?
     
  3. patrickk2

    patrickk2

    Joined:
    Dec 8, 2019
    Posts:
    92
    Hello @jukka_j!

    I was running a development build. What seemed to help was putting the actual movement in a coroutine (which made working with Lerp() easier anyways). Thanks for your response, it seems to work fine with the coroutine approach.

    Best regards,
    Patrick
     
    jukka_j likes this.