Question regarding Time scalar


What would be the best way to apply a scalar to mess with the physics timestep in order to implement slow-motion for debugging purposes? Ideally, I’d like to slow down (or even pause) physics, but not rendering, device input, or anything else for that matter.
PhysicsWorld appears not to provide a time scalar, and its Update method is called internally so I’m not seeing any way to control the passage of physics time short of modifying PhysicsWorld to support it.

Being able to pause physics time would also be useful when displaying 2D windows over the game scene, such as inventory or pause/quit/back to main menu etc. I was surprised not to find a scalar in PhysicsWorld, with a default value of 1.0


Among the PhysicsWorld methods, perhaps try PhysicsWorld::SetFps(int SimulationSubstepsPerSecond) … There is a bit more info in

Scene::SetUpdateEnabled(bool) should affect Physics as well, and is apparently used to pause when UI is active in these samples:


Thanks, I just assumed that SetFPS was an internal thing, that somehow set the delta time for the update method. I’ll give it a try.
SetUpdateEnabled sounds useful for pausing, but it won’t let me do slo-mo :stuck_out_tongue:
SetFPS can do both :slight_smile:


There’s also Scene::SetTimeScale(float).


Yeah I saw that one, thanks, I was concerned it might affect a lot more than just physics, which is why I asked about this time scaling thing in the first place :slight_smile:


scene_->SetTimeScale affects both physics and regular update deltas (it doesn’t affect any inner physics variables, just FixedUpdate is being called more or less frequently). So if you disable only physics you’ll disable only physics FixedUpdates but not regular Update (some logic could be not stopped). So, if you want to disable whole scene SetTimeScale could work better (unless when paused in menu, you rely on Update logic of that paused scene, but I assume you can run it on the separate scene).


Also, be aware that when you set 0.0 in SetTimeScale it actually sets the scale to minimum float epsilon (around 0.000001f) to prevent some problems with division by zero.


If you want things to be unaffected by a changing time scale I believe you could also use GetSubsystem<Time>()->GetTimeStep() instead.
Although this may cause issues when combined with Scene::SetUpdateEnabled(bool)?

EDIT: Or more something like @lezak’s suggestion.


Thanks for the replies, everyone.
What I want to do is to be able to pause the passage of physics time, while still having control of a camera with mouselook behaviour, and the ability to hit a key to “step” the physics manually.
This would let me closely inspect the state of physics objects at runtime.

I believe SetFPS is the one I want - I accept that components in the scene will still receive update calls at full rate, but it’s fairly trivial, at least for my custom components such as Character, to make their Update method exit early based on a static boolean, and for the Camera behaviour implementation to switch based on the same flag.

I’ll play with this tonight, as I think it will be valuable, at least for me, to be able to perform visual inspections and not rely just on breakpoints, watches and console spew.


Another way to achieve what You want is to make use of the fact that in Urho scene and application updates are seperate events. Physics update events are generated by the scene and logic components update method is using scene update.
For example I’m using this to have ‘active pause’ - controller (with camera attached to it) is using application update (E_UPDATE), so i can pause the scene (Scene::SetUpdateEnabled) and still have a fully functional (top-down) controller. It also allows me to speed up or slow down the game (Scene::SetTimeScale) without affecting the speed of camera movement.


Hey thanks, I’ll try this way too :slight_smile: My CharacterController class derives from LogicComponent. Therefore it will be paused with the Scene - my GameState class derives from Component - but it lives in a separate scene :smiley: I think this might be a good fit for me - pausing the gamescene, but not the state manager. I can add some basic mouselook camera controller to my gameplay state in order view the paused gamescene. I’m aware that I can use a camera that exists outside of any scene to view a given scene. I have a good feeling about this :slight_smile: