Acceleration calculation

Hi.

Last few hours I was trying to calculate acceleration of player movement.

I’m use school formula

v0-v/t,

but something works wrong.
My person start moving with speed 0 and just in 1.5 second he just run ahead with 230.f (2.3m/s) speed.
Here is no light speed up (Like in GTA5, or Witcher 3).
What I’m do:
I have variables:

  Acceleration = 70.f; 
   CurrentSpeed = 0.f;
   TimeTook = 0.f;
   MaxSpeed = 230.f;

TimeTook is variable that told how many time player hold on press movement buttons.
Alson I know the distance I walk while buttons pressed. (But I don’t know how to make this usefull).
And after using formula trying to calculate hero movement speed but all is useless.

Can anybody help me with this or maybe give an advice how can I fix it? Cause I feel myself very stupid and broken at moment. It’s really very ugly feelings when you can’t resolve simple math task.
Thanks.

UPD

How I handle time.

When user press button a log the time:

PressMoveButtonTime = FDateTime::UtcNow();

After, depending on that I calculate how many time button was pressed:

float seconds = (FDateTime::UtcNow() - PressMoveButtonTime).GetSeconds();
UE_LOG(LogTemp, Warning, TEXT("Time = %s"), *FString::SanitizeFloat(seconds));

Can you explain process of calculation more in detail, how do you sample time for example, what events do you use?

Hi.
I update topic and add example, how I handle time.

I do not exactly know where your formula is comming from - to my sight it isn´t even a formula.

All I can do is provide you some basic undestanding. I think you are trying to calculate the speed (not acceleration) of a player dependent on the time someone presses a movement button.
So the formula would be:

v(t) = a * t + v0

where a is your constant Acceleration, v(t) is your CurrentSpeed, v0 = 0 is a starting speed and t is the TimeTook.

So the speed after 1,5 seconds should be:

v(1.5) = 70 * 1.5 + 0 = 105

Thank you for answer.
I just want to ask… I need to calculate speed in loop using this formula while button is pressed?
Am I right?

yep I think thats the easiest way :wink:

Did it work out?