Hello,
I've got a little problem here. My timebased movement works with "Dead Reckoning"-like methods, just like this:
int Object::getX(int time)
{
return x + xDir * speed * (time - lastTime);
}
Now, I wanted to add the possibility of acceleration. For that, I just decided to add a variable called "accel" which defines the time in milliseconds which will be needed until the desired speed is reached. So, if it's 1000, the object will move in its normal speed after one second.
So I did the following:
int Object::getX(int time)
{
float timeDiff = time - lastTime;
float newSpeed;
if (timeDiff < accel)
newSpeed = this->speed * (timediff / accel)
else
newSpeed = this->speed;
return x + xDir * newSpeed * timeDiff;
}
And at first it seems to work, but it doesn't. The object accelerates, but as soon as the critical point is reached (i.e. timeDiff is > accel), the object moves slower than before. It is the correct top speed, of course, but short before that point it is moving too fast.
How can this be fixed? I'm not too good at mathematics and physics :/