Skip to main content
added 188 characters in body
Source Link
madneon
  • 295
  • 1
  • 2
  • 12

Its not very complicated, all you need is to consider 3 things:

  1. It'sBall's position (x, y) and velocity (vx and vy).
  2. GravityConstant gravity (g).
  3. Bounce conditions.

On every game loop you need to apply gravity, like:

vy += g;

Then apply velocity:

x += vx;
y += vy;

Then check these result for collision with players and/or screen edges and ground.

Depending on your game engine, you might need to "correct" these calculations by multiplying them by your current tick time (eg. vy += g * tick_time), setting proper constant gravity, and setting proper starting/after-bounce velocity (eg. vx and vy depending on player's bounce angle - you might have to use sin/cos functions).

Its not very complicated, all you need is to consider 3 things:

  1. It's position (x, y) and velocity (vx and vy).
  2. Gravity (g).
  3. Bounce conditions.

On every game loop you need to apply gravity, like:

vy += g;

Then apply velocity:

x += vx;
y += vy;

Then check these result for collision with players and/or screen edges and ground.

Depending on your game engine, you might need to "correct" these calculations by multiplying them by your current tick time.

Its not very complicated, all you need is to consider 3 things:

  1. Ball's position (x, y) and velocity (vx and vy).
  2. Constant gravity (g).
  3. Bounce conditions.

On every game loop you need to apply gravity, like:

vy += g;

Then apply velocity:

x += vx;
y += vy;

Then check these result for collision with players and/or screen edges and ground.

Depending on your game engine, you might need to "correct" these calculations by multiplying them by your current tick time (eg. vy += g * tick_time), setting proper constant gravity, and setting proper starting/after-bounce velocity (eg. vx and vy depending on player's bounce angle - you might have to use sin/cos functions).

Source Link
madneon
  • 295
  • 1
  • 2
  • 12

Its not very complicated, all you need is to consider 3 things:

  1. It's position (x, y) and velocity (vx and vy).
  2. Gravity (g).
  3. Bounce conditions.

On every game loop you need to apply gravity, like:

vy += g;

Then apply velocity:

x += vx;
y += vy;

Then check these result for collision with players and/or screen edges and ground.

Depending on your game engine, you might need to "correct" these calculations by multiplying them by your current tick time.