misterspok wrote:If you look at my code, "q" variable resresents maximum fuel usage
per second, so you can say it represents maximum thrust of an engine. To calculate fuel usage
per delta-time (maxFt) I need to do this:
If dt deviate I get different values of maxFt. Also, I use "ft" variable. It stores the value of current thrust (fuel usage). To calculate delta-V that craft acquire while burning "ft" kilograms of fuel during "dt" time I use Tsiolkovsky's equation. Note that "ft" does not change correspondingly to "dt" deviations:
Code: Select all
new_V = old_V + w * ln(craftmass / (craftmass - ft))
So, if delta-time deviate, say, 0.001 to 0.002. The result would be, that craft acuqired same delva-V during
longer period of time while travalling
longer distance. Which is not right.
Now I understand, what these equations mean. The "ft" is, indeed, implemented incorrectly. I didn't see that the first time. The "ft" stores in absolute value, how much fuel is burned in one time step (unit is kg). And that, of course, has to depend on "dt". You need to store a "fuel rate", which is in kg per second. Also the maxFt has to be stored as a rate in kg per second. Let's call this rate ftpers. Then you go:
Instead of
Code: Select all
if precFlag then
if love.keyboard.isDown("w") then
ft = ft + (0.0005 * dt);
elseif love.keyboard.isDown("s") then
ft = ft - (0.0005 * dt);
end
else ...
you want
Code: Select all
if precFlag then
if love.keyboard.isDown("w") then
ftpers = ftpers + (0.0005 * dt);
elseif love.keyboard.isDown("s") then
ftpers = ftpers - (0.0005 * dt);
end
else ...
Then the maximum check is:
Code: Select all
if ftpers >= maxFtpers then ft = maxFtpers
elseif ftpers <= 0 then ftpers = 0
end
And right before you put ft into the equation you calculate
By the way, you should also use dt for changing the angle (and use an angular velocity in "1 per second"):
Code: Select all
if love.keyboard.isDown("a") then
ang = ang - angularVelocity * dt
...
I insist so much on this point, because there are two issues with dt, namely
- implementing dt correctly
- getting reproducible (deterministic) simulations
Robins solution is a solution for the second problem. But by implementing this solution, incorrectly implemented time steps are not noticed anymore because the time step is the same in each frame. So it looks like this solution also solves the first problem. But it does not. In the end you will have variables carrying values, that are not physical, because you messed up the units (e.g. kg instead of kg/s).
If you want to get it correctly very much depends on why you write your game. If you need physically correct simulations, then you should implement everything properly. If you want something that looks good and feels smooth, then you will probably be faster if you accept some mathematical errors in the code.