-1
\$\begingroup\$

Could you please provide guidance on how to create the curved part?

enter image description here

regard,

\$\endgroup\$
3

1 Answer 1

0
\$\begingroup\$

This is basic gaming physics.

There are two general solutions. The first is call "analytical" or closed form, as it is a single equation that can give you the position of the particle/bird at any time t. See here for more:

x(t) = x0 + v0 * t + 0.5g * t^2

Link: Calculating trajectory

Where x0 is the starting position, v0 is the staring velocity, g is gravity, and t is time.

The second is approach is numerical, which is much more common in games because it allows for a lot more variety in what happens. In this approach there is an integration loop, often the game loop itself, that marches the particle/bird forward in time. Based on the current position, velocity, forces, it computes the position and velocity at the next time step:

a(t) = SUM forces(t) / mass
v(t+1) = v(t) + a(t) * dt
x(t+1) = x(t) + v(t) * dt

Each equation gives the value at the next time step based on the current time step. Position is updated by velocity. Velocity is updated by acceleration. Acceleration is the sum of all forces acting on the bird - in the simplest case just gravity. The acceleration a(t) is just a rewrite of Newton's 2nd law, F=ma. Doing this on every timestep moves the bird along the trajectory.

The reason this second, numerical, approach is much more common is greater flexibility. If your bird hits a building, or is knocked off course, or bounces on the ground, then you just introduce some new forces at any time. This would be much harder to do with a closed form approach.

It can be worthwhile to experiment with both when learning since you discover a lot about physics. There are many articles out there on basic game physics.
Link: https://www.toptal.com/game/video-game-physics-part-i-an-introduction-to-rigid-body-dynamics

\$\endgroup\$
2
  • \$\begingroup\$ In this 'x(t) = x0 + v0 * t + 0.5g * t^2 ' what do you mean by the time word? Will the bird collide with the obstacles at this time? Where should we place the pixels? \$\endgroup\$ Dec 15, 2023 at 22:34
  • \$\begingroup\$ The equation gives you the position of the bird at any time t. You plug in the time t that you want, usually the current frame time, and it tells you where along the parabola the bird is. It is not the collision time. If you want collisions the numerical approach is better. \$\endgroup\$
    – ramakarl
    Dec 17, 2023 at 2:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .