Adapting Movement to Delta-time
I've decided to implement delta-time to my game, but I can't think of a good way to adapt my current movement system to it and was hoping someone might have a solution.
My character moves in a straight line from the starting point to the destination, the movement time is calculated by distance/character speed. Here's what the code for setting the screen coordinates look like:
Code:
Always:
X = starting point.X + (moveDistance.X * (step / moveTime))
Y = starting point.Y + (moveDistance.Y * (step / moveTime))
step ++
I went for this half-assed solution in lack of any better ideas:
Code:
+ Always:
- Counter = Counter + (30 * deltaTime)
- X = starting point.X + (moveDistance.X * (step / moveTime))
- Y = starting point.Y + (moveDistance.Y * (step / moveTime))
+ Counter is greater than 1
- step ++
- Counter = 0
That solution works as long as I don't set the frame rate too low, but it doesn't feel like right way to go. Very grateful for any suggestions.