linear movement stuttering


I have problem with orthographic (2d) linear movement. Square (cube) is stuttering sometimes. Code is simple as that -

void Update()
  transform.Translate(Input.GetAxisRaw("Horizontal") * 4 * Time.deltaTime, 0, 0);

It is stuttering just awful in game preview. In standalone / web player it is much better but still noticeably. Bigger fps helps but with vsync (60 fps) still stuttering. I`ve seen related threads but no solution.

Thanks in advance.

try using Lerp instead of Translate.

1 Like
Vector3 target;

target = transform.position + new Vector3(Input.GetAxisRaw("Horizontal") * 4 * Time.deltaTime, 0, 0);

transform.position = Vector3.Lerp(transform.position, target, 1);

Tried something like this. Same stuttering not perfect smooth linear movement.

do you have camera hardly attached to your moving object or is it being controlled by another script?

Camera is not moving at all.

All I can say - try to make it not in the “Update”, but in “FixedUpdate” and make it not “4”, but “4f” so it’s definitely a floating point value.

P.S. Is this stuttering like a lot, or does it make a little “lag” from time to time?

It makes a little "lag" from time to time just as you described. But it "lags" more in game view mode than in release (standalone / web player). And I cant notice any stuttering when 200+ fps (without vsync)

No, FixedUpdate is for applying physics forces, and certainly wouldn’t help with stuttering, it would make in worse in fact since the physics framerate won’t match the display framerate.

That won’t actually make any difference since the result is a float regardless.


don’t go hard on me mate, there were my ideas of despair :slight_smile:

Thank you for your answers. Have you any idea what is the reason of stuttering or in other words a little "lag" from time to time?

my call - either unity fails to process the keyboard input correctly or it’s just an OS (or even keyboard) that doesn’t give a smooth key-repeating.

P.S. On the other hand it maybe a rendering problem…

I`ve remade input system with Input.GetKeyDown / Input.GetKeyUp and it works perfectly according to Debug.Log. Stuttering still exists. Looking for any solution. Thanks in advance.

Check your drawcalls. This happened to me and my drawcalls were 70+. I'm prototyping so I have lots of bits floating around, I got my drawcalls down to 20 and the stuttering went away.

I use clear project with orthographic camera and cube with script (only Update function). So "Stats" shows me only 1 draw call.

Ok, only other thing I can suggest is that you print out some debug info and see the vectors/floats you are using and see if they are to blame. Print to the log if they are changing too quickly.

One possible reason is a performance spike.
Many little things can cause it and it is difficult to spot them without access to the project.
From your description, the most probable is that you are not using a rigidbody with isKinematic checked, but there are many other possible causes.
Also, other tasks computer performs at the same time (e.g. other programs activity) can create this behavior.
Maybe you can upload a minimal scene that reproduces the described behavior.
Kind regards,

Hi. Thanks again for answers.
Firstly I thought that problem is in my hardware / software, but then I asked some friends to test on their computer and some of them also notice that “lag”. To notice it you should watch carefully. For example, launch standalone with 1920 x 1080 resolution and move square to left side. Then hold “right” and let square move to opposite side. At 1080 pixels it “lags” 1 or 2 times. By “lag” or stuttering I mean it jumps some pixels back and then moves normally again. With high fps (200 or more without VSync) it is not noticeable.
Here I attach clear project with problem as asked.

I have tried for ~40 minutes, the stuttering motion remains despite using many approaches.
Anybody else wanna try ?

Could it be possibly related with coordinate calculation? Maybe processor fails with rounding coordinates some times?

None have any idea? Here is releated topic - but no solution as I understand.