0

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!

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by 0x69
0

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.

0

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

Edited by DavidDD: n/a

0

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 .

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.