I am trying to move my sprite in a specific time to a specific position while using frame-independent or time-dependent movement. My sprite is also accelerated every frame to simulate gravity. I know the acceleration, the distance and the needed time. So i used the formula for acceleration based movement: s = 0,5 · a · t2 + v₀ · t + s₀ which is equivalent v₀ = (s-s₀) / t - a · t / 2. However, in my implementation the sprite does not move to the specified y-coordinate. The lower the starting y-coordinate is the higher is the resulting y-coordinate. For the time I used a quarter second. Here is my implementation:
float resultY = viewport.getWorldHeight() / 6f * 5f; float time = 0.25f; velocity.y = (resultY - circle.getY()) / time - (-25f * time / 2f);
and these are called every frame:
velocity.y -= 25f; circle.translate(velocity.x * delta, velocity.y * delta);`
What did I do wrong or is there a better method to move an accelerated sprite to a specific position in a specific time?
EDIT: I didn't mention that I want the sprite to stop at that specific point. I figured out that using my formula the sprite moves to the specified point in the specified time but it keeps moving and does not stop there. Is there a formula to solve that problem?
EDIT2: Ok, I realize that my last question is nonsense because stopping the sprite at a specified position and a specified time with a given acceleration is impossible. Thanks for all the answers.