Basic Kinematics confusion

Started by
1 comment, last by Oluseyi 15 years, 9 months ago
I tried to write a program to test my knowledge of kinematics. It does what I wanted it to do (somewhat), but the way it's implemented makes me wonder if I have the idea of kinematics down. What I was trying to do was have a single particle simulate the water of fountain. It has a initial velocity, it goes up for a while, then comes down due to gravity. I used the formula x = v0xt + (axt^2)/2 y = v0yt + (ayt^2)/2 I was under the impression that x and y in formula was "displacement" and I could "+=" (C++) the value to my game object's position. Doing this resulted int the particle shooting off the screen. If I just use "=", then I get the correct results, but that means my object can't have a initial position. I would post some code, but I'm at work at the moment.
Advertisement
That formula describes the current position at t given an initial position, initial velocity, constant acceleration. It's full form is:

x = x0 + v0_x * t + (a_x * t^2) / 2.

And similarly for y.

So there are two ways for you to solve this:

1. Remember the intial position (x0), then add those values to the position every frame, as described in the function. This, however, does not allow for any sudden changes in velocity or acceleration as you're essentially recalculating the entire path every frame.

2. Update the position (as you first tried), but use:
x += v.x * dt
v.x += a.x * dt
where dt is the change in time since the previous update. Probably the best solution in the general case. Acceleration and velocity can now change as often as you'd like.
Million-to-one chances occur nine times out of ten!
Accidental double post. The other, more recent at the time of this action, thread is here.

This topic is closed to new replies.

Advertisement