Public Group

# Pong problem...

This topic is 4118 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Right now my pong is in the works (c++ winapi project)... Currently the ball bounces off the walls at opposite angle than it was going when it hit the wall. I found out when it came to the paddle hitting the ball it has to be more complicated because the paddle also has direction/ speed... My question is what is a good way to determine the ball's new angle based on its own direction/speed and the paddle's direction/speed? I'm sure there is an algorithm of sorts.... Also if your suggesting vectors please explain to me how a vector works. Thanks, durfy

##### Share on other sites
Use vectors (the "direction in space" kind, not the standard library container :) ).

There's nothing to it. It's just a pair of numbers: the vertical speed and the horizontal speed. The two are independent of each other, so adding two velocities simply means adding the horizontal speeds and adding the vertical speeds independently.

The paddle should probably only affect the vertical component of the speed, since it only moves vertically. As to the effect it should have, consult a physics textbook.

##### Share on other sites
My paddle is horizontal type :-)
So an example of a vector would be
vector position(int x, int y) ?
thx
-durfy

##### Share on other sites
Yep, it's as simple as that. Two numbers representing movement along the x- and y-axis. This is probably how you represent your positions already, and it can just as easily be used for the speed of your ball. Think of it as two speeds in one, first the horizontal speed, and then the vertical speed. Read more about them on wikipedia.

This makes it much easier to calculate the effect you want. I've read your earlier post about this project, and it seems you are progressing nicely. However, using an angle and a speed for the ball seems a little too tricky, and I don't see any particular benefits in it. Especially not in this particular case, where you would need some trigonometric identities with multiple cos's and sin's. Not a pleasant ordeal.

Hope this get you started in the right direction.

##### Share on other sites
So a vector isn't positions at all. It's just a container for two values ... speed in this case. Couldn't this also be accomplished with a speed class?
class speed{
private:
float xspeed;
float yspeed;
public:
increaseXSpeed()
etc?
thanks,
durfy

##### Share on other sites
If we are talking about a vector in physics and math, then, a vector is just a direction and magnitude. It is merely a term. Vectors are generally associated with velocity or acceleration. If I can recall right, I believe that speed is velocity without a direction. So you can say a car goes 20mph but we have no idea which way it is going.

Positions in a technical sense would be a point.

Hopefully this is right, it has been a little over two years since my last vector calculus class :-D.

Hope that helps!

##### Share on other sites
Consult this for further analysis.

##### Share on other sites
thanks every1 that phyhsics site will come in handy!
-durfy

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 58
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632967
• Total Posts
3009558
• ### Who's Online (See full list)

There are no registered users currently online

×