#### Archived

This topic is now archived and is closed to further replies.

# Bouncing ball?

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

## Recommended Posts

I have been trying to figure this out. I made collsion detection detect so that if the ball x or y is less then 0 to go other direction and if x or y is greater then the width of the window go in the other direction but it seems as if the ball movement is not realistic its only doing like 90 and 45 degree angles I was wondering how do I make it so that it is more realistic and does not only go 90 and 45 degree angles. eg.
	double x = ball.x
double y = ball.y
double speed = ball.speed;
if(x >= 450)	{
ball.xdir = -ball.xdir;
}
if(y <= 0)// Player scores
{
user_score += 1;
ball.speed+=computer_score/10;
ball.ydir = -ball.ydir;
}
if(x < 0)
{
ball.xdir = -ball.xdir;
}
if(y >= 400) // Computer scores
{
computer_score+=1;
ball.speed+=computer_score/10;
ball.ydir = -ball.ydir;
}

coder requires 0xf00d before continue().
Killer Eagle Software [edited by - DevLiquidKnight on October 22, 2003 5:53:15 PM]

##### Share on other sites
if you start your ball out going at 90 degrees or 45 degrees... its logical that it will continue with those angles..

##### Share on other sites
You could try applying spin to your ball. That would most likely affect the trajectory when it comes in contact with a solid surface. Though I''m not entirely sure how that would be coded.

##### Share on other sites
Anyone know how to spin the ball?

##### Share on other sites
You can fake the spin. Just keep a float variable for the spin on the ball. negative spin would be counterclockwise, positive could be clockwise spin. Basically, if the paddle is moving one direction when the ball hits it, just add or subtract a value to/from that variable. Then when the ball strikes the wall, use that variable to add some bias to the ball''s angle.

fOriginalAngle = CalculateReturnAngle ();
fOriginalAngle += SPIN_BIAS_COEFFICIENT * fSpinBias;

##### Share on other sites
check this site out :

http://www.cs.unc.edu/~ehmann/RigidTutorial/

this is probably a bit than you bargained for, i haven''t read it myself yet (bookmarked it for later)... i think its relevant though...

if you are just dealing with circles and flat surfaces you can simplify stuff quite a bit... for example, the distance from the contact point to the center of mass will always be the same.

##### Share on other sites
If your rebound surfaces are at angles non-orthogonal to the ball''s trajectory you can also make it non-45.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633694
• Total Posts
3013378
×