- Home /
Is it possible to tick the fixed timestep manually or increase the timescale beyond 100?
Hello there.
I'm making an RTS game that uses NavMeshAgents and also Physics, and since these are internally managed/ticked in the fixed timestep, I decided to tick my logic in FixedUpdate() so they are in sync, everything is working wonders so far, but I'm trying to implement a "fast forward" function that is supposed to run as fast as the computer is capable of; at first I thought it was simply going to be a matter of increasing the timescale until the framerate drops considerably, but the timescale is capped at 100x, what is really slow for my game and doesn't even stress too much my computer. I can't call FixedUpdate() on all MonoBehavious manually because I need my logic to be synced with AI and Physics.
So, is there a way to either 'tick' the fixed timestep manually, or increase the timescale to a bigger value?
Thank you in advance.
Answer by AlanGameDev · Jul 18, 2015 at 02:13 PM
I couldn't find any better solution so I had to tweak all the parameters and use a timescale of 0.1 for 'normal' speed, so I could increase it up to 1000*, it wasn't as easy as multiplying all the values by 10 though, the gravity for example is around -300y, and the AI agents had to be fine tweaked, specially the acceleration and angular speed which had to be cranked substantially up. The end result is far from perfect, but I think overall the simulation is acceptable for that style of game.
To speed up as much as the computer is able to handle (not exactly though, because there's still overhead), I'm simply increasing (programmatically of course) the timescale until the framerate (i.e.: the graphics update) drops to a very low level. I think you can use that in various cases, for example, if you want to simulate many years passing rapidly, you could perhaps disable the camera and just show a progress bar, so the framerate could drop to <1 per second without problems I think (not tested though).
I'd like to have an official word on why the timescale is capped @ 100* though.
Answer by Bunny83 · Jul 18, 2015 at 03:35 AM
It seems you're confusing some things a bit. First of all FixedUpdate represents the internal physics update. Lowering the fixedtime step will increase the fixed update rate, however it won'd have an effect on the simulation speed of the physics system. Everything is scaled by Time.fixedDeltaTime
. (Note: Time.deltaTime
is equal to Time.fixedDeltaTime
when used from inside FixedUpdate).
So when you increase the fixed update rate your physics calculations just get more precise since it does smaller steps each update. You can set it to "0.001" and you will get 1000 fps for FixedUpdate. Unity will by default drop FixedUpdate calls if the catching up with the actual time takes too long and the frametime exceeds 0.3333 seconds (max allowed time step). At that point you would only have around 3 real fps.
If you want to speed up your game you should increase Time.timeScale.
If your game logic isn't time based, you might want to use your own seperate fixed update function. For this purpose i've written the CustomFixedUpdate class which allows you to have as many fixed update routines as you like. They can run at any frequency you like.
Finally i've never seen Unity to "cap" my FixedUpdate calls (unless the load is too heavy --> 3fps or worse). I just added a counter to my FixedUpdate and every second i print and reset the counter and i get a constant value and it works fine even with 10000 fps (however in my test i don't use any physics ^^).
Thank you for your answer. The question was confusing before but I've fixed that. I'm not talking about lowering the fixed timestep, but increasing the timescale OR somehow ticking the fixed step manually, however, I think you're correct that the physics uses the timescale (and the real time), so ticking the fixed timestep manually would simply improve precision ins$$anonymous$$d of increase the simulation rate. As I said, I can't manually step my logic because it is tied to the internal stepping, thus, if there's no way to increase the timescale further, I'm afraid there's no way to do what I want... I wonder why the timescale is capped at all. A solution I could think of would be to use a timescale of 0.1 for normal speed, and adjust the settings (AI speed, gravity, etc.) to achieve something believable, this way I could speed up the game to 1000x the normal speed, but that's going to be a pain to do.
@Bunny83 the curious part is that the timescale isn't capped on the lower end, it can go below zero, but not above 100, what doesn't make much sense to me.
@Bunny83 It seems there's no better way than using a lower value for normal speed, so I answered my own question and accepted that. I upvoted your answer though. Thank you.