Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Impossible to get perfectly smooth motion with Unity?

Discussion in 'Editor & General Support' started by picobots, Jun 26, 2012.

  1. picobots

    picobots

    Joined:
    Jun 7, 2012
    Posts:
    7
    Why does the motion stutter in an incredibly simple Unity game when using a fixed time step? This is a problem that has been plaguing me for years in game development (not just in Unity, but in XNA as well). Please note that I have a solid understanding of Time.deltaTime; this isn't the typical noob question about how to get smooth motion (although I'd love it if someone has an easy answer).

    I've played around extensively with turning VSync on and off, and I've tried a hundred different variations and combinations of Update/FixedUpdate/LateUpdate code, and no matter what I do, I cannot achieve perfectly smooth motion in a simple Unity game with a fixed time step. The closest I can get to smooth motion is using Update() with VSync OFF; with those settings, I get over 400fps and mostly smooth motion, but I also get some screen tearing (and the motion still isn't perfectly smooth, even with VSync off).

    Is there any way to get perfectly smooth motion in a Unity game? I'm trying to make a basic 2D game, and compared to old NES games (like Mario or Zelda), the motion in Unity is always jerky and never as smooth.

    ----

    Example Game


    Take a look at this sample game (Unity Web Player required):

    http://s3.amazonaws.com/picobots/assets/unity/jerky-motion/JerkyMotion.html

    VSync is ON, which locks the frame rate to ~60fps (synced to my monitor's refresh rate, which is actually 59.xxx Hz).

    This game has 10 cubes and 1 orthographic camera.

    There are 4 different scripts that move the camera. Only 1 script is enabled at a time, and you can switch between them using your keyboard. All 4 scripts exhibit jerky motion to varying degrees.

    ----

    Code


    1. Update (using Time.deltaTime)

    This is the smoothest of all four options (although it's close between this and LateUpdate), but every 1-2 seconds there is a "hiccup" in the motion. You can see the motion stutter and the moving cubes pause/jump slightly. Note: You need an eagle eye to see this. Look closely!

    Code (csharp):
    1. void Update()
    2. {
    3.     transform.position = new Vector3(
    4.        transform.position.x + (2f * Time.deltaTime),
    5.        transform.position.y,
    6.        transform.position.z
    7.     );
    8. }
    2. FixedUpdate (using Time.deltaTime)

    The motion stutter is very apparent using FixedUpdate. Instead of smooth movement, I see an almost constant subtle jerkiness to the motion. The cubes wobble as they move.

    Code (csharp):
    1. void FixedUpdate()
    2. {
    3.     transform.position = new Vector3(
    4.        transform.position.x + (2f * Time.deltaTime),
    5.        transform.position.y,
    6.        transform.position.z
    7.     );
    8. }
    3. FixedUpdate (using a static value)

    Same problem as #2.

    Code (csharp):
    1. void FixedUpdate()
    2. {
    3.     transform.position = new Vector3(
    4.        transform.position.x + 0.04f,
    5.        transform.position.y,
    6.        transform.position.z
    7.     );
    8. }
    4. LateUpdate (using Time.deltaTime)

    Similar to #1.

    Code (csharp):
    1. void LateUpdate()
    2. {
    3.     transform.position = new Vector3(
    4.        transform.position.x + (2f * Time.deltaTime),
    5.        transform.position.y,
    6.        transform.position.z
    7.     );
    8. }
     
    ModLunar and jpthek9 like this.
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    FixedUpdate is only for physics. Since it doesn't run at the screen refresh rate, you wouldn't be able to get smooth motion by moving things in code using transform.position. (By the way, using Translate would be simpler.) For physics, you can apply forces and turn interpolation/extrapolation on instead. I'm not sure about the webplayer, which may or may not respect vsync, but using vsync for a standalone does in fact produce perfectly smooth movement via Update here.

    --Eric
     
    OrenOthnay and sami1592 like this.
  3. picobots

    picobots

    Joined:
    Jun 7, 2012
    Posts:
    7
  4. picobots

    picobots

    Joined:
    Jun 7, 2012
    Posts:
    7
    I created an even simpler project, and I still see the stuttering issue:

    http://s3.amazonaws.com/picobots/assets/unity/jerky-motion/JerkyMotion.zip

    (210.1 KB)

    - Standalone app (Windows or Mac)
    - 10 cubes, default diffuse material
    - 1 orthographic camera
    - 1 super simple script attached to the camera (absolutely no allocation, garbage collection should not be an issue)

    Every 1-2 seconds, there's a hiccup in the motion that causes the cubes to stutter/judder as the camera pans past.
     
  5. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    It must be your scripts.
    I run 30 times what you listed and have it running smooth on an iPad. Unity is a fantastic program.
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not seeing that here, sorry. (Mac Pro, ATI 5870.) There's no memory allocated aside from 52 bytes/frame from Unity's mouse polling, which will take a long time to trigger any garbage collection.

    I'd appreciate it if you wouldn't do that. Please use one site or the other; people (including me) have been burned too many times spending our time answering a question only to find that it had already been discussed/answered elsewhere, which turns "spending time" (which is fine) into "wasting time" (which I don't enjoy at all), and it makes a coherent discussion difficult when it's divided over two separate sites.

    --Eric
     
    NinjaISV likes this.
  7. picobots

    picobots

    Joined:
    Jun 7, 2012
    Posts:
    7
    @renman3000: As linked in my second post, the project and scripts are ridiculously simple. There's only one script in the project, and it's basically impossible to write a simpler script to create motion. And I also love Unity. I've been using it happily for a year now, it's great.

    It should also be noted: I don't see this issue on iPad or iPhone. I only see this problem with a fixed time step on PC and Mac, standalone or Web Player (PC #1: NIVIDIA GT880, PC #2: Intel integrated graphics, MacBook Pro: NVIDIA GT330M). At least two other users on Unity Answers also see the problem (both standalone and web player), so I'm not alone.

    @Eric5h5: My apologies, I wasn't sure where the best place to post was. I'll keep my questions in Unity Answers going forward, thanks for the heads up.
     
    Last edited: Jun 27, 2012
  8. RoerCore

    RoerCore

    Joined:
    Oct 2, 2012
    Posts:
    1
    Did you find a solution for the problem already?
    We have the same issues with our side-scrolling game.
    With v-Sync turned off the stuttering is least visible but it's still there.
     
  9. KEMBL

    KEMBL

    Joined:
    Apr 16, 2009
    Posts:
    181
    Time.smoothDeltaTime also seems real unstable. (Core2Quatro 3.3 / 6Gb RAM / ATI 5830)

    I think core problem in Environment.TickCount Int32.MaxValue if you try to collect and than log it you can see that many log strings are equal, time not changed between Update(), in that moment things start unstable moving.

    I duno other time source but if it exists, you can try to count delta from it for you self.
     
    Last edited: Nov 8, 2012
  10. carmine

    carmine

    Joined:
    Jan 4, 2012
    Posts:
    394
    I believe you need to smooth out FixedUpdate with Time.fixedDeltaTime (instead of Time.deltaTime)
     
    racheljcorey likes this.
  11. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    runs smooth on my machine and I have low specs win 7 32 bit intel express chipset g41. using Chrome browser
     
  12. BPPHarv

    BPPHarv

    Joined:
    Jun 9, 2012
    Posts:
    318
    According to docs Time.deltaTime is the recommended use for both Update and FixedUpdate function calls as Time.deltaTime automatically returns the proper delta time in both update and fixed update functions.

    http://docs.unity3d.com/Documentation/ScriptReference/Time-fixedDeltaTime.html
     
  13. jroge

    jroge

    Joined:
    Dec 4, 2012
    Posts:
    2
    i really suspect that this has to do with the display used.
    i also ran into this problem. testing it revealed the following:
    i works well on the laptop display (60 hz) and it starts to jerk on the secondary display (59.9 hz).
    it's even jerky when i start the standalone-game on my secondary display and then move the window to the laptop display.
    and if i start it on the laptop display and then move it to the secondary display it's working without any stutter.
    i tried the same game on a different laptop (without a secndary dispay) and it was quite smooth.
    (all tested on a mac with osx 10.8)

    best
    jroge
     
  14. vahid62

    vahid62

    Joined:
    Sep 2, 2012
    Posts:
    2
    The problem is cameras, You must have only one camera enabled in scene. first delete MainCamera in new project and use First person camera for your project
     
  15. jroge

    jroge

    Joined:
    Dec 4, 2012
    Posts:
    2
    no it has nothing to do with cameras. it also happens with only one camera and a simple cube.
     
  16. dasbin

    dasbin

    Joined:
    Jan 14, 2012
    Posts:
    261
    I always get stuttery motion in Unity when Vsync is on (even if the system is capable of rendering the scene at 600fps or something). I don't know what the the problem is, but I've just resolved to always turn Vsync off for PC and Mac.

    On the other hand, looking at your examples, clearly you will get stuttery motion when moving in FixedUpdate. You are moving it by a discrete amount every fixed update cycle (which is normally far fewer times per second than your graphical frame rate), so you will see those discrete jumps.
    To get smooth motion in FixedUpdate, move only using forces or rigidbody.velocity, and turn on Interpolation or Extrapolation on the rigidbody's settings. This will smooth the motion in graphical frames between fixed update frames.

    I apologize if I'm wrong here, but your code examples give us exactly the impression that you don't actually have an understanding of Fixed Update at all, and therefore this is a very typical noob question about how to get smooth motion.
     
    Last edited: Feb 18, 2013
  17. iWoundPwn

    iWoundPwn

    Joined:
    Feb 16, 2013
    Posts:
    212
    Tested the scripts out like everybody else said the script runs fine on my machine as well as some android and iDevices.
     
  18. OverridingTrombe

    OverridingTrombe

    Joined:
    Dec 17, 2012
    Posts:
    6
    Tested. Interestingly I get the same problem as him. Using the latest Unity 4. Reproduceable jerkiness on a new Unity 4 install too (in different clean computer. Both PC are


    gaming rigs) and android tablet Asus TF700 JellyBean.

    Time.deltaTime seems to be only reliable if I use Lerp routines for movement, but if using it in Update() for movement, it jerks the movement a lot ( around each 3-4 sec ish). VSync is off (for all quality settings), and also unless it goes more than 70 ish fps, it is quite noticable.

    I don't remember seeing this while using Unity 3.5.7 (I'll reconfirm in a few days.)
     
  19. EvilNoodle

    EvilNoodle

    Joined:
    Nov 17, 2011
    Posts:
    31
    Hey,

    I don't know if you are suffering from the same thing I was but for me this was caused by a disparity between what different things thought my screen refresh was.

    See http://forum.unity3d.com/threads/142754-linear-movement-stuttering

    Hope that helps. If not then I hope you find the solution you are looking for!

    EvilNoodle
     
  20. chilton

    chilton

    Joined:
    May 6, 2008
    Posts:
    561
    Hi,

    I'm seeing the same thing here, Macs, PCs, iPhone, and iPad. Everything from a high end Retina display Mac down to a crappy iPad 1. It's ugly, across the board.

    Unity 4.1.2f1

    I'm hopeful one of these other links will have a solution, and if I find it, I'll report back.

    -Chilton
     
  21. 90DegreeDesigns

    90DegreeDesigns

    Joined:
    Oct 28, 2013
    Posts:
    16
    I know i'm late to the choppy movement party thread, but I seem to have some pretty fluid motion now. I'm making a ball-and-paddle game and I was having trouble with touch that it would only recognize movement a split second into the actual touch, causing the paddle to jerk across the board. So here is what I had done to smooth motion:

    Code (csharp):
    1. var timespeed : float = 2;
    2.  
    3. function Update () {
    4.  
    5. if (Input.touchCount > 0
    6.  
    7. Input.GetTouch(0).phase == TouchPhase.Moved)
    8.  
    9. var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
    10.  
    11.  
    12. //plugged in the Y value to the Z transform on purpose, because I want it to move back and forth with no y movement.
    13.  transform.Translate (touchDeltaPosition.x * ((timespeed * 2f) * Time.deltaTime), 0 , touchDeltaPosition.y * ((timespeed * 2f) * Time.deltaTime)) ;
    14.  
    15.   }
    16. }
     
  22. terraKote

    terraKote

    Joined:
    Apr 3, 2014
    Posts:
    9
    Hi guys, I have same problem. I have a 2D game, and I need when player activates a trigger, door smoothly move from point A to point B. Here's my code:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class DooorSystem : MonoBehaviour {
    6.  
    7.     public Transform point1;
    8.     public Transform point2;
    9.     public Transform door;
    10.     private bool _canOpen = false;
    11.  
    12.     public void OpenDoor(){
    13.         _canOpen = true;
    14.     }
    15.  
    16.     void Update(){
    17.         if(_canOpen)
    18.             door.transform.position = Vector3.Lerp(transform.position, point1.position, 2f * Time.deltaTime);
    19.     }
    20. }
    21.  
    22.  
     
  23. Lance9527

    Lance9527

    Joined:
    Jul 4, 2012
    Posts:
    12
    Sorry to bump this ancient post, but do you solve this problem finally?
     
  24. JayG81

    JayG81

    Joined:
    Sep 4, 2012
    Posts:
    72
    I'm going to bump this again, but I don't think there is a solution to this. Been searching for one for literally 2 years...
     
  25. 0mr_ashutosh0

    0mr_ashutosh0

    Joined:
    Jul 9, 2014
    Posts:
    5
    Well, has anyone found the solution yet ?
     
  26. chilton

    chilton

    Joined:
    May 6, 2008
    Posts:
    561
    Dunno, but I still see it when I click that webplayer link.

    Oddly enough, I don't see this in my own games anymore.
     
  27. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    This is something that really needs to be addressed by Unity. The problem is incredibly common, and game-breaking.

    Smooth gameplay is a requirement for any competent developer.

    Denying the problem exists simply because you can't see it or your monitor/system doesn't display it, is just asinine.
     
    MikawasakiDigital likes this.
  28. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Unity is fine here. When using fullscreen standalone, it's very smooth. You need to test full screen standalone, not windowed standalone. Also in my case, AVG does a giant crap on smoothness.
     
    CarterG81 likes this.
  29. funshark

    funshark

    Joined:
    Mar 24, 2009
    Posts:
    225
    Visible on a nexus5 ( android ) with an endless runner.
    It seems to be much less visible when getting ride of the Time.deltaTime
    ( simple translate in Update )
     
  30. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Tried Time.smoothDeltatime ?
     
  31. funshark

    funshark

    Joined:
    Mar 24, 2009
    Posts:
    225
    Yes, it has smoothed the hiccups but they are still there :)
    The best result so far is to get ride of the Time.deltaTime, but I still can't understand why
     
  32. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  33. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    Also having this issue. Just tried using Translate rather than Update, seems to be even more choppy.(I'm showing 90fps in stats though) I've noticed this issue since I started using Unity about 2 years ago...
     
  34. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    One thing I noticed is that the Unity Editor is full of bugs and performance issues.

    I've chased "bugs" before, only to find that they are not bugs at all in the build, just the Editor.

    So if you haven't already, make sure the bug is in the build of your game, not just the Editor.
    I hope that helps.
     
    devezone likes this.
  35. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    This issue perplexes me to this day.

    Yesterday, I had smooth movement. Smooth enough. I did very little, merely optimizing a bit of code- and my standalone builds become extremely jerky- even when I try with an empty, fresh scene or another person's example. Today, the problem was worse than usual, so I stop work out of frustration, have a snack, and return an hour later. I touch nothing, build again, and it runs flawlessly- smoother than I've ever seen it. The computer wasn't touched from when I left it until when I returned.

    The only thing is that I closed Unity for that entire time, and just now opened it, then hit Ctrl-B. Smooth, despite an hour before being really choppy.

    Performance stats and framerate are excellent no matter if it hitches/lags or is butter smooth.

    I also looked at some examples and the stuttering is very prevalent on there, for both my monitors. However, it's different for each (they stutter "differently"). Even when my standalone build is smooth, that example never is.

    Different monitors/systems explains why some get the stuttering while others don't. Some see this a problem, some don't even have it.

    What is strange though, is this is centric to Unity for the most part. I tested many other games, other engines, my own engine- and none have this issue (for me) except Unity. Can't be my code, because it happens with an empty project, in all examples of people showing the problem off, all possible ways of moving an object/camera, etc.

    Unity just doesn't play nice with some monitors, I guess. I've read about a hundred fixes which indicate the problem can have numerous causes. From GPU/Windows settings, to hardware itself being the problem. Although the problem does appear in other engines for SOME people, it seems Unity is more of a culprit than anything else. As I said, for me- Unity is the only thing which gives me this problem. Even then, it's sparadic- off and on, even when nothing is changed.

    The speed of the gameobject moving and even the graphics/colors in the scene will make it more/less obvious. This can also explain why some people report the hitching and others don't. Sometimes it's just not noticeable to any but the dev himself.

    My only conclusion is that it is indeed impossible to get perfectly smooth motion in unity in most circumstances. (You posting that you have smooth motion does not resolve the problem for everyone else). Hopefully, those who play unity-made games will simply not notice (or not even have) the hiccups.
     
    Last edited: Mar 25, 2015
    Chris75 likes this.
  36. Chris75

    Chris75

    Joined:
    Jan 31, 2015
    Posts:
    41
    I agree with you Carter.

    Unity makes it impossible to get perfect smooth movement. I also am making a linear game and while I got the stuttering down to a minimum, it all comes to what you said "hoping that no one notices it"

    Luckily all my friends do not notice it. But I notice it greatly and when I finally point it out to them, they notice it too.

    I have searched endless hours online and found nothing. Some people see the issue, some don't.

    The weird thing is that recently, my game works very good on my S4, but on my brother's S5, there stuttering is worse than on my phone (which currently only stutters around 5% of the time compared to how it used to stutter around 50% of the time). I have yet to try it on an iPhone since you need an Apple based computer for to even test it.

    But to fix my issue, I had to change my Quality Settings to a default "Fantastic!" for my Android build.
     
  37. jsip

    jsip

    Joined:
    Jan 25, 2015
    Posts:
    8
    FixedUpdate is out of phase with framerate. That's pretty much it. You will still shift if setting the fixed timestep to 0.01666666 or 0.16666667 as you will always have a remainder over a period of 1s or 60 frames. There is nothing you can do about physics being out of phase with your framerate.

    You can roll your own using transform.translate in Update. We use this method for Xbox One and PS4 for our 2D game and its smooth as silk. It had taken me about a month (part time, thanks day job) to create pixel perfect smooth motion and collision but its definitely the way to go.

    Several video captures for testing and the results are always the same across both consoles, PC, Mac and Linux.

    I rarely touch FixedUpdate due to the phase shift except for quick one-offs nobody will notice.
     
  38. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Bleh, stop necroing old threads.

    I opened the thread. Looked at the original poster's webplayer, even imported his example and only when I had to upgrade his example project to Unity 5 did I notice this thread is years old.

    But anyways, I just wanted to add that the motion in the original poster's example is perfectly smooth for me and that I'm extreeeeeeemly anal about this sort of thing. I've not had any smoothness issues with Unity whatsoever. So stop claiming that this is a persistent issue with Unity. It's something with your game or setup, it certainly doesn't affect all of us. It may be a bug, but it's an elusive one if so.
     
  39. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    For what it's worth, I just tried the web player demo and it was very jerky on my machine. I get very smooth motion in my game, but I'm using rigid bodies so it's a different ballgame.
     
  40. Chris75

    Chris75

    Joined:
    Jan 31, 2015
    Posts:
    41

    I'll look into that. My code is:

    Code (csharp):
    1.  
    2. transform.position = new Vector3 (transform.position.x + (speed1 * Time.deltaTime), transform.position.y, transform.position.z);
    3.  
    I found this to be the best solution for getting as smooth as possible movement. Still stutters here and there though. So I'll try using translate.
     
  41. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    Could the repeated "new" instead of using a Vector3 that was created by the class directly be making matters worse at all? I could be mistaken but I think the garbage collector has to clean all that up which can cause little hiccups. Maybe the profiler might show that? Why allocate new memory for a Vector3 every time something moves?

    It's probably more than that, maybe it's something about how Unity does things internally, but anything to smooth out the hiccups and pauses in the framerate is bound to help at least a little bit, I'd think.
     
    Chris75 likes this.
  42. Chris75

    Chris75

    Joined:
    Jan 31, 2015
    Posts:
    41
    You know, someone else mentions about looking into the garbage collector awhile ago when I posted my issue.

    I spent about a month trying to get it perfectly smooth.I tested it in so many ways. I think I even made a level with only 4 objects moving and it stuttered. If only 4 objects cause it still, then I figured the garbage collector wouldn't help much. But I may totally be wrong and hope I am.

    I've heard to look into Object Pooling, read about the Garbage Collector, and now to try transform.Translate.

    I hope one of them fixes it but since I tried a small project with 4 objects moving, my hopes aren't that high. But it never hurts to try new things!
     
  43. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    Yeah, you're probably right about the garbage collector on so few objects. Maybe it'll help, maybe not. It's a quick and easy thing to try anyway.

    One thing I'm curious about is if that time function might be getting a different value for every object or if it's the same number every time the function is called in a given frame. I don't know how it works internally, it could be done either way.

    You've probably tried a million things already, but if you haven't done so already, maybe this might be an idea: I'd try just writing out to the console the value of the delta time function for each object every frame for a few frames. See if they all match on any given frame. What I'd be looking for aside from typical small scale noise are bigger spikes where the number suddenly doubles or more. I know in the profiler there is typically a fair bit of spiking in my game. It's not huge, but it's a fairly regular pattern where every few cycles I'll have functions take two or three times as long as they normally would.

    I was the physics engine developer on VRC Pro for fourteen years and had to battle this kind of thing at a low level. I remember two of us spending a full day doing nothing but investigating the best we could how Windows was taking priority away from my physics thread which caused similar spiking that was totally out of my control. This varied a lot between windows versions, I remember XP being a lot smoother than Vista (this was a long time ago, obviously). Not saying that's the case you're running into necessarily, it just reminds me of that.

    In my case with VRC it was possible to get things to run pretty smoothly because the physics rate was much higher than the frame rate which is the opposite of what people normally do in Unity (most people think things have to work that way, but they normally don't in high fidelity simulations like racing sims and so forth). My physics ran at 1/500th or 1/250th of a second timesteps, 5 or 10 times higher than people normally use in Unity, so the cars actually all moved several times before every graphics update. Because of that I didn't have to bother with any smoothing/extrapolation each frame like Unity does where multiple graphics frames are rendered between two consecutive physics steps.

    I have a sneaking suspicion this all might just come down to the variations in timing from one frame to the next. In VRC I was able to analyze it at the CPU clock cycle level, so ultra high precision timing was available. Even then, in order to keep things smooth in my version of FixedUpdate() I didn't use the time that passed from one frame to the next, but a total time delta that had passed since the scene was loaded. I compared that with the total time that had passed since the last frame and used the difference as the measurement of time, basically. This ironed out a lot of the little hiccups, but I'm not sure if you really have the capability of doing something like that with Unity.

    I'd have to think about it, but it may be like jsip said, that to get things smooth enough to your liking with Translate and so forth instead of rigid bodies you might just have to roll your own solution. Annoying I know, but if Unity can't or won't improve this then there may not be much choice.
     
  44. Chris75

    Chris75

    Joined:
    Jan 31, 2015
    Posts:
    41
    Sent you a PM Todd :)
     
  45. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Not to be rude here, but have you guys tested this with other engines or seen it be smoother in other games and thus know what you trying to achieve? And is it achievable on your machine?

    Also, have you tried different monitors? There can be big differences between monitors and input lag, ghosting etc. can be interpreted as jerky motion.

    And lastly, I decided to try this myself. In the editor and on a standalone build everything is silky smooth. In the webplayer I get an occasional hiccup or screen tear (once every 5-30 seoconds) with or without vsync. How often this occurs also seems to depend on the browser and I suspect it's not much Unity can do about it because it's probably a browser render issue. But like I said on standalone or in the editor it is as smooth as it's physically possible to get it, even on my 120Hz monitor.

    I tried this with Translate and Rotate on a bunch of cubes.
     
  46. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    After looking at the original web player demo from a couple years ago again, it looks like all the objects are moving in lockstep to my eye. The stuttering on my machine in that demo is quite severe, mostly it looks like a severe pulse about once every second.

    jsip I think has the best answer so far. That 0.02 timestep is going to be a problem if you're vsynching to 60 fps with 0.0166666 in FixedUpdate. What'll happen is every few frames the objects won't move at all (or maybe they'll move twice, I might have that backwards). So for one frame every now and then you get a stutter or a jump where nothing moved or things moved further than they should have.

    Here's what I'd try if you're using Translate or moving the positions directly rather than using physics: Assuming you can live with running at 60 fps, forget about deltaTime and just hard code 0.016666 (or 0.02 or something else, it probably won't matter what number if the physics aren't being used), move everything in Update() and see if there's any difference.

    To get things really sweet like jsip sounds like he's done, you'll probably have to put in some work and really think a lot about what's happening from frame to frame, how the timing functions really work, etc.. Depending on what you're doing you might be able to get by with a hard coded value to replace the time delta in Update() and just do everything there, forgetting about FixedUpdate() and the associated functions entirely.

    One problem is that the 60 fps is kind of a dumb number for a vsync rate because of the remainder jsip talked about. If it were 50 you could have a FixedUpdate() rate of 1/50 = 0.02. I guess the next step up would be at 80 where you could use 0.0125, etc., stuff you could represent exactly with a floating point number. 0.01666666... and similar numbers are an inherent problem.
     
  47. Chris75

    Chris75

    Joined:
    Jan 31, 2015
    Posts:
    41
    I don't think you are being rude.

    My issue actually comes up in my Android builds. On my PC builds, with Fantastic! settings, it's flawless.
     
  48. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,079
    Chris, maybe you could post the videos you PM'd me for TwiiK to see and chime in on. Those really looked to my eye like the operating system grabbing time slices out of the app, especially with it being so different between different phones. If that's the case you're talking about, it wouldn't have anything to do with Unity really. The only thing I could think to do would be to see if you can increase the priority of the app somehow. I'm not a mobile guy so don't know about these things on phones. Maybe someone else can explain it.
     
  49. Chris75

    Chris75

    Joined:
    Jan 31, 2015
    Posts:
    41
    Good idea Todd. Again, thank you so much for trying to help.
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No...Vector3 is a struct; new local structs are created on the stack, not the heap, so there's no garbage collection involved.

    --Eric
     
    Todd-Wasson likes this.