Jump to content
• Advertisement

# Bouncy Ball

This topic is 4388 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

Im trying to get a ball to bounce off a paddle with the specific physics it should have like pong, can n e 1 tell me where i can find the algorithm?

#### Share this post

##### Share on other sites
Advertisement
How are you moving the ball around? That'll affect how you make it change directions.

#### Share this post

##### Share on other sites

basically i dont know, i used some code that im sure really aint doing too much check out my code. but lets say that you swing the paddle down really quickly before the ball hits, when the ball hits the paddle depending on the direction you swinged the paddle, the balls vector and velocity will be effected by this motion of the paddle.

im making another function coz i know the one below sux and just aint right!!!

int moveBall(){		MinPaddleY = PaddleY - 1.5f;	MaxPaddleY = PaddleY + 1.5f;	MinPaddleY2 = PaddleY2 - 1.5f;    MaxPaddleY2 = PaddleY2 + 1.5f;	Dist = (BallX - PaddleX) - 1.0f;	Dist2 = (BallX - PaddleX2);	if (Dist < -1.5 && BallY > MinPaddleY && BallY < MaxPaddleY  && BallX > -5.0)	{		blnBallX = true;	}		if (Dist2 > -1.5f && BallY > MinPaddleY2 && BallY < MaxPaddleY2 && BallX < 5.0)	{		blnBallX = false;	}		if (BallX < -7.0f)	{		++Player2Score;		Player2Score = (Player2Score + 1.0f) - 1.0f;		blnBallX = true;			}	if (BallX > 7.0f)	{		++PlayerScore;		PlayerScore = (PlayerScore + 1.0f) - 1.0f;		blnBallX = false;					}	if (blnBallX == true)	{		BallVX = cosf(BallAng) * 0.2f / 8;		BallX +=  BallVX;		--Xrot;	}		if (blnBallX == false)	{		BallVX = cosf(BallAng) * 0.2f / 8;		BallX -=  BallVX;		++Xrot;	}		if (BallY < -3.8f)	{		blnBallY = true;	}		if (BallY > 3.8f)	{		blnBallY = false;	}	if (blnBallY == true)	{		BallVY = cosf(BallAng) * 0.2f / 8;		BallY += BallVY;			}		if (blnBallY == false)	{		BallVY = cosf(BallAng) * 0.2f / 8;		BallY -= BallVY;	}		return 0;}

#### Share this post

##### Share on other sites
Well I think that above all, you should change your ball movement so it is not frame-rate dependant as you have it in your code, when you achieve this and everything runs time-dependent everything you learned in physics will work better. maybe for the collision with the paddle y would recommend to try and calculate as if the paddle was half a circle and calculate the point it would hit, that way you just invert the angle with the tangential curve that passes through the circle at the intersection point and it will make the ball bounce at a different angle when hits the paddle on different parts. Please tell me if I made myself clear lol, I am not used to write this kind of things but I could make a drawing for you.

#### Share this post

##### Share on other sites
mhhmmh, what about this??

http://img107.imageshack.us/img107/1042/eaea6lu.jpg

hope it helps :D

EDIT: oops, I readed your text too fast, and didn't notice that you kind of wanted it for 3D ..

well, I guess the general idea of my drawing still applies, you should just add something to hold the paddle's """"" spin """"".

also.. for my thinking, you should store the vertical and the horizontal angles separately, and also have two "spin" variables for the ball and other two for the paddle.

plus, with this "spin" calculation you could nake the ball alter it's course when it hits the table (thing that also happens on real pong)..

#### Share this post

##### Share on other sites
So basically you're asking how to put 'english' on the ball
where the motion of the paddle at the time of impact can have a small effect on the ball's bounce direction

uhh, I'd simply add a tiny fraction, say 5%, of the paddle velocity onto the ball's reflected velocity.

#### Share this post

##### Share on other sites
I just noticed, my force equation isn't right, the "amortiguation" constant should be multiplying the sum of forces or speeds.
It should be of values like " 0.8 " or something, because if it would be 1, then the ball would bounce of a perfectly elastic way (thing that doesn't happen in real world), also, if the value would be greater than 1 the ball would do something like "create energy" and accelerate more than it should..
so, for putting it short, the force equation should be:

F3 = (F2 + F1) * amortiguation

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5
• Advertisement

• 9
• 33
• 41
• 23
• 13
• ### Forum Statistics

• Total Topics
631745
• Total Posts
3002006
×

## 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!