Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Slow motion in DOTS (Havok Physics)

Discussion in 'Physics for ECS' started by hauwing, Nov 29, 2020.

  1. hauwing

    hauwing

    Joined:
    Dec 13, 2017
    Posts:
    69
    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.
     
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    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.
     
  3. hauwing

    hauwing

    Joined:
    Dec 13, 2017
    Posts:
    69
    Hi petarmHavok thanks, unfortunately DeltaTime does not work as well... thanks
     
  4. Arberk

    Arberk

    Joined:
    Feb 3, 2014
    Posts:
    5
    Here is code from my TimeControlSystem:

    Code (CSharp):
    1. simulationGroup = World.GetExistingSystem<FixedStepSimulationSystemGroup>();
    2. simulationGroup.Timestep = defaultTimeStep * timeControl.Scale;
     
    petarmHavok likes this.
  5. hauwing

    hauwing

    Joined:
    Dec 13, 2017
    Posts:
    69
    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.

    Code (CSharp):
    1. public class SetTimeStepSystem : SystemBase
    2. {
    3.  
    4.     public float normaltimescale = 1f;
    5.     public float slowtimescale = 0.1f;
    6.     public float defaulttimestep = 0.01666667f;
    7.  
    8.     protected override void OnUpdate()
    9.     {
    10.  
    11.         var simulationGroup = World.GetExistingSystem<FixedStepSimulationSystemGroup>();
    12.  
    13.  
    14.         if (Input.GetKeyDown(KeyCode.LeftControl))
    15.         {          
    16.             simulationGroup.Timestep = slowtimescale * defaulttimestep;
    17.             Debug.Log("slow motion " + simulationGroup.Timestep);
    18.         }
    19.  
    20.         if (Input.GetKeyDown(KeyCode.LeftShift))
    21.  
    22.         {
    23.             simulationGroup.Timestep = normaltimescale * defaulttimestep;
    24.             Debug.Log("Normal " + simulationGroup.Timestep);
    25.          
    26.         }
    27.     }
    28. }
     
  6. Shane_Michael

    Shane_Michael

    Joined:
    Jul 8, 2013
    Posts:
    158
    You also have to remember to set Unity's "Time.timescale" to match your timescale variable otherwise you will just get a slideshow.
     
  7. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
    Occuros and florianhanke like this.
  8. hauwing

    hauwing

    Joined:
    Dec 13, 2017
    Posts:
    69
    Thanks all, UnityEngine.Time.timeScale works, thanks