by potash · 12y ago · 0 comments
Can someone comment on the game's physics? I am assuming:
- constant horizontal velocity
- gravity
- flapping implemented via impulse
- collisions are handled with bounding boxes
Maybe someone who knows something about optimal control (ODE) say whether this is analytically solvable? Of course there's still the practical stuff (numerical integration, I/O lag) to deal with but I'm optimistic.Set flap_height = bottom of next pipe + constant.
If bird height < flap_height, flap.
Done!
threshold_height = bottom_of_pipe_height + 10 pixels; // or something
if (current_height < threshold_height)
flap
else
don't flap
If you never flap when above the threshold, you will not hit the top. Let distance between ground and top of screen=100.
Bird position after a flap at y=y0, time=t0:
y(t) = y0 + 13.8 - 147 * (t - t0 - 0.288)^2
(https://news.ycombinator.com/item?id=7229018 -- note the original comment had "+ 0.288", but if you plot the graph this was obviously a mistake)I tried it out in my own HTML5/JS Flappy clone (mine's not at all interesting or even done, but I felt I had to give it a try), and the movement seems really accurate.
I have no idea how they got to those numbers, however.