SLH
May 23rd, 2007, 11:36 AM
I'm creating a 2D game that supports replays by creatubg keyframes every time the object's properties change not according to a formula.
Currently i'm moving the object using the following formulas (where Timing.dt) is the amount of time passed:
float XChange = Velocity.X * Timing.dt + Acceleration.X * (Timing.dt * Timing.dt) / 2.0f;
float YChange = Velocity.Y * Timing.dt + Acceleration.Y * (Timing.dt * Timing.dt) / 2.0f;
Position.X += XChange;
Velocity.X += Acceleration.X * Timing.dt;
Position.Y += YChange;
Velocity.Y += Acceleration.Y * Timing.dt;
However, what i'd like to be able to do is, when replaying, jump straight to time t, rather than have to continually apply this algorithm in a loop until i get from my keyframe, to the required time. Unless i'm mistaken, if i change Timing.dt the object's position won't end up the same for a given time (i.e. i can't double Timing.dt and do half as many steps).
So i want a formula for the object's position at time t, given it's initial position, initial velocity and acceleration (constant).
Any help is, of course, greatly appreciated.
Currently i'm moving the object using the following formulas (where Timing.dt) is the amount of time passed:
float XChange = Velocity.X * Timing.dt + Acceleration.X * (Timing.dt * Timing.dt) / 2.0f;
float YChange = Velocity.Y * Timing.dt + Acceleration.Y * (Timing.dt * Timing.dt) / 2.0f;
Position.X += XChange;
Velocity.X += Acceleration.X * Timing.dt;
Position.Y += YChange;
Velocity.Y += Acceleration.Y * Timing.dt;
However, what i'd like to be able to do is, when replaying, jump straight to time t, rather than have to continually apply this algorithm in a loop until i get from my keyframe, to the required time. Unless i'm mistaken, if i change Timing.dt the object's position won't end up the same for a given time (i.e. i can't double Timing.dt and do half as many steps).
So i want a formula for the object's position at time t, given it's initial position, initial velocity and acceleration (constant).
Any help is, of course, greatly appreciated.