I've always used a fixed timestep for physics, and I think I have a pretty good understanding of the basics.
However, something I don't see addressed in any articles is how to program things in a timestep-agnostic way, such that you can change the fixed timestep value during development and still have everything moving along the same curves.
Let's say I have the following example code for moving a platformer character; I've tried to include the full range of tools needed for movement: velocity, acceleration, and damping. This is written assuming it will be called at a fixed frequency:
run_speed = 2; //velocity
brake_decay = 0.95; //viscous damping/exponential decay
gravity = 1; //acceleration
if(button_pressed) vel_x = run_speed;
else vel_x *= brake_decay;
vel_y += gravity;
pos_x += vel_x;
pos_y += vel_y;
If my fixed timestep is currently A ms/tick, and I want to switch to a timestep of B ms/tick, AFAICT I need to calculate three new scaling factors, something like:
run_speed = 2*A_to_B_vel; //velocity
brake_decay = 0.95*A_to_B_damp; //viscous damping/exponential decay
gravity = 1*A_to_B_acc; //acceleration
My question is: what formulas should I use for each scaling factor? And, do I need to modify the rest of the simulation code in any way (eg do “ vel_y += gravity * dt^2 ”), or should rescaling these three factors be sufficient?
(NOTE: I realize that by changing the size of the fixed timestep, the positions of objects won't match exactly (because we'll be sampling a curve at a different frequency); my goal is for the objects to be moving along an identical curve regardless of the sample rate.)
For bonus points: is there any way to implement “bullet time” in such a simulation? More generally, what I'd like is to be able to freely alter the timescale of the simulation without changing the fixed-step size, so that when prototyping I can easily experiment with the speed of the entire world to find what feels best. For example, what do I do if I want to slow everything down by 20% while maintaining identical trajectories for all objects? Intuitively this seems equivalent to my original question, i.e. it's about altering the duration of each tick while maintaining the same trajectory curves.
Hopefully someone can point me in the right direction. About 10 years ago I successfully converted a fixed-step simulation from 40hz to 60hz, maintaining an identical feel, so I know it's possible. In fact, IIRC I asked on these same forums and got a great answer.. sadly with the new redesign, I can't find that thread anymore! So I was hoping someone knowledgeable could shed some light. : )
Thanks!