Hello there!

I am pretty new to game developing but got a book and a library called CDX.

The first chapter is about creating Pong as it is a very simple game. But I would like to make it a bit more complicated than just negating the X and Y velocity of the ball whenever it hits things, so I thought:
Why not make the ball bounce depending on where it hits the paddle?

So what I would like to do is just setting the balls Y speed (I have the paddles on the left and right corners of the screen) depending how high/low the ball hits the paddle. So if it hits the middle it keeps the Y, and depending on how high/low it hits the paddle I want to set the Y value to a higher/lower value. So if I hit it at the very top the paddle, the Y velocity should be pretty high, but if I hit the centre of the paddle it's not very a very high value at all.

If you understand what I mean and if you feel like helping feel free to post!

In my opinion I at first tried to implement new ball speed as superposition of ball speed and paddle speed. In vector form it would be:

V_ball_new = V_ball + V_paddle

Results should be interesting too.

Good luck.

In my opinion I at first tried to implement new ball speed as superposition of ball speed and paddle speed. In vector form it would be:

V_ball_new = V_ball + V_paddle

Results should be interesting too.

Good luck.

Hmm yes I think I tried doing that but it failed miserably because it set the speed to something that's way too high. I need to up my resolution to be able to do this as I am working in a 640x480 space. Also I think I would have to divide the result by X to make it not go too fast.

I'll think about it and see if I can get a nice result! :) Thanks

Actually.. Come to think of it I use this

Ball->SetVelY((Ball->GetPosY()+7)-(Paddle2->GetPosY()+50));

Where I add 7 to the ball pos and 50 to the paddle pos to get the center of them, because the ball is 15x15 and the paddle is 100x20.

But the ball gets a massive speed even if I divide it by 1000 for some reason..

EDIT:

I had it from the beginning.. I was just stupid enough to forget a very simple mathematical rule:

Multiplication and division first.

Ball->SetVelY(((Paddle2->GetPosY()+7)-(Ball->GetPosY()+50))/10);

There.... Solved

Hmm yes I think I tried doing that but it failed miserably because it set the speed to something that's way too high.

You can have several solutions here:
1. Just normalize ball speed to interval V_norm=0..1 . Then *real* ball speed would be V_Max * V_norm . (V_Max - greatest possible speed of ball)
2. Or just limit paddle possible speed into 0..Max_paddle_speed .

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.