Changing Simulation Time
Summary
Use Time.TimeScale to adjust server physics simulation times, or to stop the physics simulation from advancing.
Description
Reactor server scripts can set the value of Time.TimeScale to change the rate of physics simulations and even pause physics updates by setting the time scale to zero. The default physics time step is based on the server frame rate, which at 60fps is 16.666ms. This value is then mulitplied by Time.TimeScale when advancing the physics simulation. The time simulated on each frame is tracked and synced to connected clients. Changing the time scale will change the value of Time.Delta on both the client and server. To get the unscaled time, use Time.UnscaledDelta.
The ksRoomType component has a property named 'Apply Server Time Scale' which can be used to couple the server timescale time with the Unity timescale. Enable this property if you want the Unity time scale to match the synced server time scale.
The following example code defines an RPC handler which will increase or decrease the time scale by a constant factor. Add this RPC method to a server room script and invoke Room.CallRPC(0, true) or Room.CallRPC(0, false) in a client room script to change the server time scaling.
ServerRoomScript RPC Handler
[ksRPC(0)]
public void ChangeTimeScale(ksIServerPlayer player, bool increase)
{
if (increase && Time.TimeScale < 10.0f)
{
Time.TimeScale *= 1.25f;
ksLog.Debug("Time scale = " + Time.TimeScale);
return;
}
if (!increase && m_spawnRate > 0.1f)
{
Time.TimeScale /= 1.25f;
ksLog.Debug("Time scale = " + Time.TimeScale);
return;
}
}ClientRoomScript RPC Call
Last updated

