Archived

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

DevLiquidKnight

Bouncing ball?

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


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


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


Link to post
Share on other sites