Ouveaus
Ouveaus

Reputation: 31

Unity Vector2.MoveTowards stutter

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.

Upvotes: 0

Views: 1204

Answers (1)

Perazim
Perazim

Reputation: 1549

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...

Upvotes: 1

Related Questions