Jump to content
  • Advertisement
Sign in to follow this  
Durfy

Pong problem...

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!