So I know how timestepping works.
As I understand it if I wanted to move a character at the same speed in real-world time I need to simply multiply the movement of the character by DT on each frame.
So code without timestepping
player.position.x += 1
and with timestepping
player.position.x += 1 * dt
I have noticed that it is frustrating in some cases to do it like this. Because lets say I had a specific distance in mind for the player to travel in the frame, without timestepping I only need to add that ammount, however with timestepping I need to find a different value that produces the same results when multiplying by a "normal" dt value.
I was wondering how I could approach the following.
I want to move the player forward one unit each frame as long as the fps is 60. So I am going to call a function with moveForward(1) every frame. However if the fps is 30 I want the player not to move one unit but instead travel 0.5 units each frame but still call moveForward(1). So basically if their is no lag it travels 1 unit each frame if their is lag it still travels at the same "real world" speed but in code travels less far each frame.
My question is. How would one calculate it? Perhaps you could fill in this skeleton function.
var targetDT = (1.0 / 60.0)
var currentDT = //**Value changes each frame to represent currenty delta time of frame**//
func moveForward(units: Int)
var scalar = //**IDK what goes here something that considers the fps**//
player.position.x += units * scalar;
This is probably very simple math I am just not figuring it out!
Also what is the relationship between dt and fps if we consider that the render loop and logic loop happen at the "same" time simultaniously?