I asked a similar question a few hours ago, but I think there was too much information in that question so I deleted that one and made this one more relevant.
I'm trying to move an object with a decreasing acceleration in a specified time but the acceleration reaches 0 before the object reaches the destination.
I calculate acceleration like this:
//Linear acceleration starts at 0 and finishes at 2. acceleration = this.elapsed / (this.duration / 2.0f);
Acceleration will be a value between 0 and 2 depending on how much time has elapsed. The value will be closer to 2 when elapsed is closer to (total) duration.
So to calculate a deceleration I would do:
//Linear deceleration starts at 2 and finishes at 0. acceleration = 2.0f - this.elapsed / (this.duration / 2.0f);
This appears to work just fine but the decelerating object never reaches the destination, at around 99% of the distance the elapsedTime becomes greater than total duration, causing the acceleration to become negative. In other words, it appears to have decelerated about 1% too fast.
The original acceleration works perfectly, so does the linear velocity. It's just the deceleration that isn't working properly.
Am I doing something wrong?