Search Unity

  1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

linear movement stuttering

Discussion in 'Editor & General Support' started by Demion, Jul 7, 2012.

  1. Demion

    Demion

    Joined:
    Jul 7, 2012
    Posts:
    13
    Hi.

    I have problem with orthographic (2d) linear movement. Square (cube) is stuttering sometimes. Code is simple as that -
    Code (csharp):
    1.  
    2. void Update()
    3. {
    4.   transform.Translate(Input.GetAxisRaw("Horizontal") * 4 * Time.deltaTime, 0, 0);
    5. }
    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.
     
    Last edited: Jul 7, 2012
  2. vladk

    vladk

    Joined:
    Jul 10, 2008
    Posts:
    128
    try using Lerp instead of Translate.
     
  3. Demion

    Demion

    Joined:
    Jul 7, 2012
    Posts:
    13
  4. vladk

    vladk

    Joined:
    Jul 10, 2008
    Posts:
    128
  5. Demion

    Demion

    Joined:
    Jul 7, 2012
    Posts:
    13
    Camera is not moving at all.
     
  6. vladk

    vladk

    Joined:
    Jul 10, 2008
    Posts:
    128
    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?
     
  7. Demion

    Demion

    Joined:
    Jul 7, 2012
    Posts:
    13
    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)
     
    Last edited: Jul 7, 2012
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,216
    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.

    --Eric
     
  9. vladk

    vladk

    Joined:
    Jul 10, 2008
    Posts:
    128
    don't go hard on me mate, there were my ideas of despair :)
     
  10. Demion

    Demion

    Joined:
    Jul 7, 2012
    Posts:
    13
    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?
     
  11. vladk

    vladk

    Joined:
    Jul 10, 2008
    Posts:
    128
    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...
     
  12. Demion

    Demion

    Joined:
    Jul 7, 2012
    Posts:
    13
    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.
     
  13. markTheDesigner

    markTheDesigner

    Joined:
    Sep 12, 2009
    Posts:
    14
    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.
     
  14. Demion

    Demion

    Joined:
    Jul 7, 2012
    Posts:
    13
    I use clear project with orthographic camera and cube with script (only Update function). So "Stats" shows me only 1 draw call.
     
  15. markTheDesigner

    markTheDesigner

    Joined:
    Sep 12, 2009
    Posts:
    14
    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.
     
  16. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,443
    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,
    -Ippokratis
     
  17. Demion

    Demion

    Joined:
    Jul 7, 2012
    Posts:
    13
    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.

    https://dl.dropbox.com/u/59043948/test.zip
     
  18. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,443
    Hi,
    I have tried for ~40 minutes, the stuttering motion remains despite using many approaches.
    Anybody else wanna try ?
     
  19. Demion

    Demion

    Joined:
    Jul 7, 2012
    Posts:
    13
    Could it be possibly related with coordinate calculation? Maybe processor fails with rounding coordinates some times?
     
    Last edited: Jul 8, 2012
  20. Demion

    Demion

    Joined:
    Jul 7, 2012
    Posts:
    13
    Last edited: Jul 9, 2012
  21. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    19,438
    Got profiler stats?
     
  22. Demion

    Demion

    Joined:
    Jul 7, 2012
    Posts:
    13
    I guess its pro only? Could you please check project attached some posts ago?
     
  23. Demion

    Demion

    Joined:
    Jul 7, 2012
    Posts:
    13
    Any help?
     
  24. Tbug

    Tbug

    Joined:
    Jul 10, 2012
    Posts:
    3
    HI,

    I have the same probleme with the free version, i tried some Transform and physics move method, but i think a part of the answers is in your previous link , the problem is link with the Time.deltatime and the computer activity, but I don't know how to reduce this lag effect.
     
  25. EvilNoodle

    EvilNoodle

    Joined:
    Nov 17, 2011
    Posts:
    26
    Hey

    If what you are seeing is a stutter like it is dropping a couple of frames on a regular pattern of every 1 to 2 seconds then I had this exact same problem.

    I had a movement judder every one to two seconds with just a cube moving in front of a static orthographic camera. I was scaling movement by delta time and also tried both the update and fixed updates, direct transform manipulation, physics movement etc. At one point I got so frustrated I made my own timer based on calculating the system up time manually, calculated frame time from that and scaled accordingly but yet the problem persisted.

    I abandoned work on my project and loaded up the Angry Bots demo. I had to take out the rain effects and a bunch more atmospheric stuff to see it but once the distractions were gone there it was - the dreaded stutter!

    This problem drove me nuts over about four weeks and even pushed me to re-install Windows to see if that was the issue! - NO JOY!

    I tried switching engines to see if it was Unity specific or a system level issue and noted that the same thing was happening with the JMonkey engine beta so I started looking at the rest of the system to try and identify the cause.

    In the end I traced it back to what appeared to be a discrepancy in the reported refresh rate for my monitor (dell 27").

    Windows was reporting it as 59 hertz while the NVIDIA control panel was reporting it as 60. I figured competing refresh rates could possibly introduce some kind of jitter especially as my jitter was about once every second or so. To test I manually set up a new custom profile for the monitor in the NVIDIA control panel at 59Hz to match the windows value and the problem suddenly vanished and has not returned since.

    I have no idea if this is what is happening to you and it is possible that this refresh discrepancy has absolutely nothing to do with it and it just fixed itself but if you have an NVIDIA card it might be worth trying this as it seemed to fix it for me! Now the NVIDIA control panel still reports 60Hz but the stuttering is gone.

    I really hope this helps but if not I would recommend checking out the angry bots project and disabling the rain etc (I manually switched the renderers off in the inspector during play mode) to see if it is happening there or is specific to your project and perhaps grabbing a copy of JMonkey or another engine and seeing if you get a similar jitter before treating it as a Unity specific issue.

    Regards

    EvilNoodle
     
    CarterG81 likes this.
  26. EvilNoodle

    EvilNoodle

    Joined:
    Nov 17, 2011
    Posts:
    26
    Following on from my last post I just downloaded your test project and checked it at 2560*1440 with visuals set to fantastic and from a build it is as smooth as silk. A slight judder is present in the editor but it is irregular and I find things run a little slower in the editor in general.

    EvilNoodle
     
    Last edited: Jul 11, 2012
  27. Demion

    Demion

    Joined:
    Jul 7, 2012
    Posts:
    13
    Thank you very much, EvilNoodle. Seems like setting 60 hertz (was 59 previous) in windows settings really helped.
     
    Last edited: Jul 11, 2012
  28. EvilNoodle

    EvilNoodle

    Joined:
    Nov 17, 2011
    Posts:
    26
    No problem, really glad it helped!

    This problem drove me nuts!

    Of course you will need to remember to inform your users somehow to do the same if they see a similar juddering in your end product so they don't think it is shoddy workmanship on your part.

    Happy coding

    EvilNoodle
     
  29. maxamundo

    maxamundo

    Joined:
    May 29, 2013
    Posts:
    1
    I had the juddering movement described here. The cause in my case was I moved the camera based on the player x position, so the camera moved a fraction after the player causing a flicker. If I put the camera as a child of the player the camera moved up and down with the jumping, I couldnt work out how to restrict child object movement in the y-axis. There is no flicker when the camera is a child of the player. So I guess the gameObject update() transform.position method works different than a child object.
    So I have made the camera only move when the player moves near the screen edges.

    hope this helps.
     
  30. StKiller

    StKiller

    Joined:
    Oct 23, 2014
    Posts:
    1
    So, after a half a week of researching, playing with displays' frequency (I have two, they run at most 60 Hz), trying all kind of stuff:
    http://answers.unity3d.com/questions/275016/updatefixedupdate-motion-stutter-not-another-novic.html
    http://forum.unity3d.com/threads/smoothmovementtest-should-help-eliminating-hiccup-sources.162694/

    I finally found solution for my issue on this thread, unrelated to Unity3d:
    http://www.tomshardware.co.uk/forum/386158-33-setup-rhythmic-stutter-vsync-enabled

    So, basically, f.lux application interferres somehow with the vsync. When I completelly close it - no more stuttering!
     
  31. jasonthefish

    jasonthefish

    Joined:
    Jan 18, 2015
    Posts:
    5
    OMG @StKiller thank you so much for this tip. The stuttering in my game was driving me crazy, and closing f.lux completely fixes it. Thank you very much for posting the tip here!
     
  32. snlehton

    snlehton

    Joined:
    Jun 11, 2010
    Posts:
    89
    Hi,

    I was struggling with this same issue. About to shoot some clips for a game trailer with these settings: vblank on, 1280x720 fullscreen and 60 fps target.

    The framerate was just horrible: running 60 fps but constant jittering:

    upload_2015-4-22_12-11-11.png

    Then I tried without vblank but forced vsync on from NVIDIA panel (together with triple buffering). Jittering was still very noticeable. However, the profiler looked like this -- so in engine's perspective it was running smoothly.

    upload_2015-4-22_12-13-55.png

    Then I enabled the DX9/DX11 excluse mode and BOOM. All problems solved. The game was running super smooth (still with some super rare jittering, probably due to some loading/instancing etc):

    upload_2015-4-22_12-21-51.png

    upload_2015-4-22_12-18-13.png

    The warning you get is right. Alt-tabing away from the app made it stop responding.

    BTW I'm using MSI Afterburner to record the footage. The codec I'm using is NVIDIA's nvenc:

    upload_2015-4-22_13-9-4.png

    This allows me to capture 60 FPS videos in H.264 format (AVCHD, and only MKV is supported). We needed to re-encode the videos to proper h.264 format using VirtualDub in order to bring them into After Effects. But that is problem with AE not supporting the MKV/AVCHD. Otherwise the videos work just fine in Mediaplayer etc.

    Hope this helps someone...
     
  33. Hiti3

    Hiti3

    Joined:
    Jul 16, 2015
    Posts:
    7
    What about andoid / ios??? How to turn DX9/DX11 settings?
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,216
    Only Windows uses DX9 or DX11; all other platforms use some kind of OpenGL or custom API.

    --Eric
     
  35. snlehton

    snlehton

    Joined:
    Jun 11, 2010
    Posts:
    89
    In the end we ended up doing frame by frame capture to PNG on disk and then stitch them to lightly compressed AVI's using VirtualDub and Lagarith codec. This was needed to get perfect, stutter-free 60fps FullHD video for our Greenlight trailer.

    On iOS/Android, I would use something like Elgato HD60: https://www.elgato.com/en/gaming/game-capture-hd60 or fake the video by capturing Unity standalone build (maybe with the same trick we did above)