Jump to content
  • Advertisement

Archived

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

DevLiquidKnight

Bouncing ball?

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

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
Advertisement
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 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

  • Advertisement
×

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!