pong ball movemet?

 DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

#### Hybrid View

1. Registered User
Join Date
Jul 2004
Posts
83

## pong ball movemet?

Hey does anyone know how to make the ball bounce like it does in pong? Like if it is going towards the bottom of the screen it bounces up at the angle its supposed to?

2. Senior Member
Join Date
Feb 2004
Posts
541
Well I would store the velocity of the ball as an X and Y value (with X and Y having the usual definition for a cartesian coordinate system, X being horizontal and Y being vertical). This would be the velocity that the ball was travelling in say pixels per unit time.

When the ball hits the edge you want it to rebound from the surface at the same angle that it hit it, at the same speed that it hit it. The velocity would have the same magnitude, but would be of opposite sign in the appropriate direction.

For example if the ball hits the bottom or top edge at velocity (X,Y), it will change it's velocity to (X,-Y). If it hits the left or right edge at velocity (X,Y) it will leave at velocity (-X,Y). Obviously this is a very simplistic model. It doesn't allow for spin or for friction. The ball will just keep bouncing around forever at the same speed. That may be ok for playing pong though.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise