0
votes

I'm unable to create a smooth Unity 2d Object movement. I'm using function Vector2.MoveTowards(position, destination, speed * Time.deltaTime). I literally create empty 2d project, put in single 64x64 png, create single script and attach to this object.

Project View The code

I also tried using, Update, FixedUpdate, LateUpdate, rounding MoveTowards results, modifying Time settings, suing Time.deltaTime, Time.smoothDeltaTime, Time.fixedDeltaTime. Also tried to calculate passed distance manually(instead of MoveTowards) based on the passed milliseconds between FixedUpdate() calls. It is literally empty project with single script and single object and it stutters. Computer resources are available, Unity priority is set to Realtime or High.

1
I cant recreate your stutter even on my craptop..It is also important to read How to Ask, tour] and minimal reproducible example as it is generally disapproved of that links to pictures of code etc, as its not searchable - BugFinder
I placed all the code which is supposed to be searchable as text. - Ouveaus
As I said though I cant recreate from this, what spec is your machine? - BugFinder

1 Answers

1
votes

Using deltaTime may give stutter at lower framerates or at higher movement speeds. Try to use deltaTime movement in combination with either lerping or a interpolated rigidbody:
Example for lerping:

transform.position = Vector3.Lerp(transform.position, wantedPosition, Time.deltaTime * lerpSpeed);

Example for moving with rigidbody:

myRigidbody.MovePosition(wantedPosition);

But this are just snippets, so look up in the documentation. For using interpolation with rigidbody, Unity created a tutorial. And I guess you can find a lot of other guides...