# Calculate distance based on - Resistance - Acceleration - Time - Initial Velocity

I have been looking at equations that can represent how far something travels given these three variables. Initial Velocity, Resistance, Acceleration, and Time.

The main thing I saw which was similar was a calculation for free falling and air resistance. However, the only problems which I encountered when looking at these were that they included the Gravity variable. Which kind of represents my acceleration variable in this formula. However, there is the possibility for there to be no acceleration acting upon the object, and only a resistance factor. So when I would substitute 0 it seems like the equation wouldn't work.

So there is the possibility for this formula to have 0 values for resistance acceleration. Initial velocity will most likely have a value.

For context: I am working with a game that simply has air resistance. And I am just trying to calculate distance as part of the game loop with a time factor between each loop iteration.

### Edit:

To add a bit more context surrounding what I went down. What I found was the when the game loop for the server and the game loop for the client was running at different speeds, it would then give the object a different velocity and location after x time because the resistance was being applied twice as fast as the client. or vise versa. So there was no real resistance applied over a T time per se. And it seemed to be happening at an interval. So I was trying to determine how far something moves, based on the time rather than each interval, so that no matter the speeds each interval is, they are in sync with the location.

I had a look at a couple of these:

Calculate the free fall distance of an object with air resistance

Distance travelled in free-fall

But could not work out how to integrate for example, when there is no acceleration and only a resistance factor (if you were to imagine travelling in space with an air resistance in one direction, (so no gravity)).

• It might help if you wrote out what you found that you don't think would work and also clarify what it is you're looking to do. If you're building a game the simplest answer is likely just to do an Euler approximation to Newton's equation each physics frame. Apr 8 at 0:13
• Hey, @RichardMyers I just provided a bit more information, let me know if that makes it more clear. Apr 8 at 1:33
• While here you might be able to get something here that would allow you to produce estimates that can be checked every few frames to force synchronization, this question would likely do better on, say, stack overflow or something. Server client physics synchronization is not a new problem and depending on the needs of your application, I'm certain there are other solutions people have worked out. Apr 8 at 2:32

So for these kind of problems, I'm no programmer by any means, but the easiest way to proceed seems to be to use Newton's second law, $$F = ma$$, with $$F = Force$$, $$m = mass,$$ and $$a = acceleration$$. In doing so, I'm assuming that the mass of whatever thing you're considering to be subject to air resistance has constant mass.

So we have to consider the forces acting on our object. We have gravity, which is $$-mg\vec{k}$$, with $$\vec{k}$$ the unit vector in the vertical direction. And we also have air resistance, which is typically well modelled by a force of the form

$$-[\alpha v+\beta v^2]\hat{v},$$ with $$\alpha$$ and $$\beta$$ constants, which you can set to change the way your game works, $$v$$ the magnitude of the velocity vector, and $$\hat{v}$$ the unit velocity vector. This should be a good model unless you need the air resistance to depend on the orientation of the object, in which case things get a lot more complicated, but I can still try to help.

This gives us $$F = ma = -mg\vec{k} - [\alpha v+\beta v^2]\hat{v}=m\frac{d\vec{v}}{dt}$$ So redefining our constants, we have, for the acceleration $$\frac{d\vec{v}}{dt}=-g\vec{k} - [\alpha v+\beta v^2]\hat{v}$$ To first order for a small time step $$\Delta t$$, we get a change in velocity $$\Delta \vec{v}$$ given by $$\Delta \vec{v} = (-g\vec{k} - [\alpha v+\beta v^2]\hat{v})\Delta t$$.

Then if $$v$$ is your old velocity, then after one timestep, the new velocity is $$v+\Delta v$$. And so the distance moved in the next timestep should be $$\Delta x = [v+\Delta v]\Delta t$$.

• I realise my comment is quite sloppy on vector notation - my apologies, it is late where I am and I don't have the motivation to fix it at the moment, but I shall get to it in the morn.
– MC2k
Apr 8 at 0:25
• Hey @MC2k, Thanks for the answer, the orientation is not so important, I think it will take a bit to try get my head around this, Apr 8 at 7:07
• In that case I would recommend just using the bottom-most equation and $\Delta v$ as I have shown, and just playing around with the constants $\alpha$ and $\beta$ until you get an air resistance that you like (it's even reasonable to set one, but not both, equal to zero if that's desirable). If you have objects of different sizes you may wish to add a proportionality to object area/length into your constants as well.
– MC2k
Apr 8 at 13:43