Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Changing timestep affects speed of timestep-invariant objects

Discussion in 'Physics' started by Derakon, Aug 30, 2019.

  1. Derakon

    Derakon

    Joined:
    Jul 3, 2019
    Posts:
    20
    I have a FixedUpdate that looks like this:

    Code (CSharp):
    1.     public void FixedUpdate() {
    2.         float vx = Mathf.Sin(rocker.heading * Mathf.Deg2Rad);
    3.         float vz = Mathf.Cos(rocker.heading * Mathf.Deg2Rad);
    4.         Vector3 force = new Vector3(vx, 0, vz) * curThrottle * thrust * Time.deltaTime;
    5.         hull.AddForce(force, ForceMode.Acceleration);
    6.     }
    I recently discovered that if I want to have smoothly-moving particles, I have to drop my physics timestep from .05 down to something smaller. Doing that caused all of my ships to slow way down. Even if I remove the Time.deltaTime multiplier in the above code, my ships don't have identical performance across different physics timesteps.

    Is this fundamentally unavoidable? I don't plan on changing the timestep frequently, I'm just trying to understand the systems involved.

    Also, is there some way to have my particles move smoothly despite having a relatively chunky physics update? My particles aren't interacting with other objects, they're purely aesthetic.
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,497
    This is the error. An acceleration is a time-independent magnitude. Remove Time.deltaTime, adjust your magnitudes accordingly and the movement will be independent of the timestep.