Hi everyone!
I would like to make an Air Hockey game in pygame.
I was wondering if it was possible to have 'proper' bouncing (ie. the puck goes in a direction relative to the angle the paddle hit it in).
I can easily write the rest of the code.

Thank you
Mark

Recommended Answers

All 6 Replies

Most pygame tutorial give you an implementation of simple bouncing. An ideal round ball hits on an ideal straight wall without spinning and losing energy.

For example:
http://www.pygame.org/docs/tut/intro/intro.html
http://www.penzilla.net/tutorials/python/pygame/

I am not sure I know what an air hockey game is. The only difference I can think of, can be the spin of the ball or curve like surfaces or deformation of bodies.

Is that the problem?

google 'air hockey game'.
then play one.

The problem is, the angle that the puck moves in after you hit it at a certain angle with the paddle. It's all the angles!

I have found some games.

You must add the paddle's momentary velocity to the pucks velocity*-1 in a vectorial way.
That means if the paddle is not moving, then the velocity of the puck after the hit is -1*velocity before the hit. As expected.

well that as well.
But, as i said in the 1st and 3rd post, its the angle that the puck moves in after you hit it at a certain angle.

If you have the velocity vector you have the angle of it.

If the puck comes in with the velocity vector (-1,-2), and the paddle is moving with (3,4), then the velocity vector of the puck will be -1*(-1,-2)+(3,4)==(4,6)
The angle of (4,6) is arcus tangent (6/4), or any other arcus trigonometric function can be used.

Thanks...theres one problem.
Im 13, and ive just had dinner.
Could you explain the equation in a simpler way please?

Thanks anyway :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.