|
-
May 23rd, 2007, 11:36 AM
#1
Thread Starter
Not NoteMe
Calculating position given initial position, velocity and acceleration
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:
Code:
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.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
May 23rd, 2007, 08:04 PM
#2
Re: Calculating position given initial position, velocity and acceleration
To find the X position of something at time T, the formula is:
x(t) = x0 + vx0*t + (1/2)a*t2
where:
x0: initial x position
vx0: initial velocity in the x direction
a: acceleration
t: time.
Repeat the forumla with the y components to find the Y position.
Hope this helps!
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
May 24th, 2007, 08:24 AM
#3
Thread Starter
Not NoteMe
Re: Calculating position given initial position, velocity and acceleration
Thanks, that's what i thought it was, but the fact that somewhere i read that i had to alter the velocity at each time step (which i don't think is the case if i used that formula) i was getting a touch confused.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|