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
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
SetFPS can do both
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
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
Although this may cause issues when combined with
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.