- Home /
Proper Fixed Timestep for 30 FPS
Hello.
I am having this issue, where my whole game jitters (Small fast jumps every few seconds).
The game runs on iOS device with about 40 FPS, but i've decided to limit it to 30FPS with Application.targetFrameRate.
The problem is that if i leave the fixed Timestep to 0.2 or 0.25 the game jitters all the time. It's pretty tiny jitterring and barely noticeable, but it's there.
So i've decided to set the Fixed Timestep to 0.033333, which shoud be for 30 fps. Anyway, the game now runs super smooth, but these jitters occurs at some point, (Like every 4, 5 seconds).
I am reading from 2 days, what's been discussed in the forums the jitter camera problem, from the LERP, but there's no clear answer on that. My player moves with FixedUpdate and the camera follows it with FixedUpdate...
So my questions are:
What is the proper Fixed Timestep for 30FPS?
If the game can run with 40, 45FPS, shoud i limit it to 30, or leave it on it's own?
What coud be causing the jitter if the game runs with good FPS? When i limit the game to 30FPS and when i monitor the FPS, its allmost perfectly staying on 30FPS (It goes from 29.94 to 30.05). So coud these variations cause the jitter every few seconds, if the Fixed Timestep is 0.033333 ?
Any advice will be appreciated, to stop that jitterring...
Thanks
Answer by Bunny83 · Nov 02, 2014 at 02:09 PM
Never, ever move your camera in FixedUpdate. FixedUpdate will never be in sync with the visual update. You should move your camera in LateUpdate in most cases. Increasing the fixed timestep (so lowering the fixed framerate) will just increase the possible jitter (the amplitude of the jitter). When you use FixedUpdate i guess you use rigidbodies and the physics system. If not, get your code out of FixedUpdate and move it to Update. However if you use the physics system only keep stuff in FixedUpdate that is really physics related. Everything else should be in Update or LateUpdate.
Since we don't know very much about your project it's difficult to give any more precise advices.
(Some time ago i made this FixedUpdate simulation to show how it's actually working)
I was just going to write, that before someone advicing me to move the camera movement to Update, i allready did that. Doesn't help... And why everyone gives that advice, when Unity, in both their tutorials "Project - S$$anonymous$$th" and "Project - Survival Shooter" are moving their cameras in exactly FixedUpdate. If it's that wrong, woud they do it this way? I think this whole problem is not involving at all the movement of the camera, because i tested everything. I tried Lerping the camera, i tried with smoothDamp in both Update and FIxedUpdated. DOesn't work. The game still jitters. And it's not only the camera....
THere are no rigidBodied, that the camera follows, just a character with CharacterController. But isn't it physics object? As far as i know the CharacterController moves under the rules of FixedUpdate, so if i make my camera to follow it with Update, the character will start jumping (forth / back).
Also, if highering the FixedTimestep will make the things worst, why it smooths the movement? When i set the FIxedTimestep to 0.02 the camera movement jitters all the time, when i set it to 0.03333, it jitters once, every 4, 5 seconds, which is better in some way..
Thanks for the help :)
The character controller isn't physics related. It does it's own collision detection. $$anonymous$$oving the CharacterController in Update will never make it jump forth and back. That would most likely happen when you move the camera in FixedUpdate ins$$anonymous$$d of LateUpdate, I've never looked at any of the recent tutorials, but just for reference i'm just downloading it...
Yes the s$$anonymous$$lth project works with a rigidbody and not with the character controller. When using a rigidbody you have to move it with FixedUpdate and you will always have some sort of jitter. In the s$$anonymous$$lth project they move the camera in FixedUpdate to remove the character jitter. On the other hand everything else will jitter. Since they use a smooth damping for the camera and the framerate is quite hight the jitter isn't that visible. Try lowering the fixedTime step to 0.03333 and set a targetframerate of 30 and you will also have a jitter every now and then.
How often you see the jitter depends on the interference frequency of both, the visual framerate and the fixed framerate. If they are almost the same, the difference between those two frame rates will be a very slow frequency (something between 0.5 and 0.01 Hz). However the amplitude of the jitter depends only on the fixed-framerate. When i'm playing the s$$anonymous$$lth project in the editor at 300fps and move the camera in update, everything is smooth except the character. But if i set the fixed timestep to 0.001 ( == 1000fps) the jitter isn't visible anymore. That's because i get about 3 physics updates between each visual frame. The amount the player is off is just a tiny fraction of the movement that happens between each update.
To $$anonymous$$imize the jitters amplitude and frequency you would have to increase the fixed framerate to a exact multiple of your visual framerate. Since they will never be in sync you will still get that jitters every now and then, but the higher your fixed framerate, the smaller the jitters will be.
Of course you can't push the fixed framerate too much, especially on mobile, but if you use FixedUpdate it's impossible to remove the jitter completely.
Thanks a lot for the explanation, that makes some sence.
Anyway I am wondering, if my camera follows the player with the Update, shoud my player also move with the Update? If my player moves with FixedUpdate and Camera moves with Update there shoud not be jitter, cuz the camera refreshes faster than the player right?
What's weird also is that, if i lower the FixedTimestep to 0.01 the framerate of the game falls down to 17 FPS. If i keep it at 0.02 or 0.025 it stays at 30FPS. So the verry small Fixed Timestep impacts the FPS?
the game is for iOS i don't know if i mentioned that..
ANd one more thing. I will make the FixedFramerate to be 40, ins$$anonymous$$d of 30. But what shoud i do with Fixed TimeStep?
Shoud i leave it to 0.02, or make it 0.033333?
thanks
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Can I change movement from Unity 3d into Unity 3D iOS 2 Answers
Why target frame rate either 60 or 30, how about 50? 3 Answers
How to make an object moving in a certain direction, move in specific steps like 0.1f 1 Answer
GameObject.FindGameObjectsWithTag - How CPU Intensive is it (iOS)? 1 Answer