Slow motion in DOTS (Havok Physics)

Hi,

May I know how to implement slow-motion effect in the current DOTS Havok physics environment? I had some old codes to multiply UnityEngine.Time.fixedDeltaTime by a certain multiplier (eg. 0.05) by it does not work anymore after several updates of the packages.

I am currently with
Entities - 0.16.0
Havok - 0.4.1
Unity Physics - 0.5.1

Thanks.

After moving to the FixedStepSimulationSystemGroup, both physics engines now step at the Time.DeltaTime rate. So you might want to tweak that one instead of the fixedDeltaTime you did previously.

If that doesn’t work, we’ll try to see if I can give you a workaround for this.

Hi petarmHavok thanks, unfortunately DeltaTime does not work as well… thanks

Here is code from my TimeControlSystem:

simulationGroup = World.GetExistingSystem<FixedStepSimulationSystemGroup>();
simulationGroup.Timestep = defaultTimeStep * timeControl.Scale;
1 Like

Hi Arberk thanks, but seems it only slow down the frame rate like running on a very slow computer, rather than smoothing the motion slowly.

Below is my code, mind sharing your code for reference? thanks.

public class SetTimeStepSystem : SystemBase
{

    public float normaltimescale = 1f;
    public float slowtimescale = 0.1f;
    public float defaulttimestep = 0.01666667f;

    protected override void OnUpdate()
    {

        var simulationGroup = World.GetExistingSystem<FixedStepSimulationSystemGroup>();


        if (Input.GetKeyDown(KeyCode.LeftControl))
        {          
            simulationGroup.Timestep = slowtimescale * defaulttimestep;
            Debug.Log("slow motion " + simulationGroup.Timestep);
        }

        if (Input.GetKeyDown(KeyCode.LeftShift))

        {
            simulationGroup.Timestep = normaltimescale * defaulttimestep;
            Debug.Log("Normal " + simulationGroup.Timestep);
          
        }
    }
}

You also have to remember to set Unity’s “Time.timescale” to match your timescale variable otherwise you will just get a slideshow.

@hauwing , did you try playing with UnityEngine.Time.timeScale?
I just tried it quickly, seems to do the trick on our HelloWorld scene.

2 Likes

Thanks all, UnityEngine.Time.timeScale works, thanks