Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Paddle / Ball Physics
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mr. T




PostPosted: Sun Aug 05, 2007 6:52 am   Post subject: Paddle / Ball Physics

I want to add some paddle / ball physics to my Breakout game, because having the ball only change direction when it hits the paddle is boring. What kind of physics / math should I be using, and where do I start? Thanks in advance.
Sponsor
Sponsor
Sponsor
sponsor
cavetroll




PostPosted: Sun Aug 05, 2007 11:51 am   Post subject: Re: Paddle / Ball Physics

If you find out which half of the paddle the ball hits you can either make the y-speed slower or faster. This might work but I would need code to Know for sure. Also it could be done using thirds, or even smaller segments.
Mr. T




PostPosted: Sun Aug 05, 2007 11:19 pm   Post subject: Re: Paddle / Ball Physics

Here's my code. Try playing around with it to see if your idea is feasible.
I think though that it's also important to consider the direction of the paddle when the ball hits it (not just where it physically hits the paddle).



BreakOut.zip
 Description:

Download
 Filename:  BreakOut.zip
 Filesize:  6.37 KB
 Downloaded:  204 Time(s)

Aziz




PostPosted: Mon Aug 06, 2007 10:22 am   Post subject: RE:Paddle / Ball Physics

Instead of just reversing x-direction when it hits a baddle, why not actually use reflect physics? When an object bounces off a solid surface at and angle, it rebounds at the same angle. Light is a great example of this. Take for example

code:


\          /
 \        /
  \      /
   \    /
  a \  / b
_____\/_____
############



The angle a and the angle b are the same angle.

Check out my tutorial to make a ball more in directions other than the standard 8:

http://compsci.ca/v3/viewtopic.php?t=13404&highlight=constant+speed
Mr. T




PostPosted: Wed Aug 22, 2007 6:39 am   Post subject: Re: Paddle / Ball Physics

I took a look at your code, Aziz, but I'm not sure how this is applicable to what I'm trying to accomplish. I want the movement and direction of the paddle to the affect the angle at which the ball bounces off the paddle.
Aziz




PostPosted: Wed Aug 22, 2007 8:17 am   Post subject: RE:Paddle / Ball Physics

Oh, movement and direct of the paddle. Sorry. So I assume that you already have your ball moving in directions and speeds you want it.

Okay, then, you'll have to figure out exactly what reaction you what. I believe you want to follow some standard set of physics laws?

Well, go get a basketball and bounce it on even ground (make sure the ball does not spin). It should go directly up.

Now bounce it, but this time spin it backwards. (Make sure it falls straight down). It will bounce back towards you.

Third time, do the same thing, except bounce it forward, while spinning it backwards. You can get the ball to bounce back at you (and the spin on the ball will probably cease).

If you didn't actually do it (I wouldn't have), just just me it works. This applies to your problem because you can image that if the paddle is moving when the ball hits it, it's going to put spin on the ball.

So if a ball is going at an up-right direction towards the paddle, and the paddle is travelling at a downward speed, I believe the angle of reflection would increase (meaning it would have a lesser y-speed). Either that or the other way around.

Pretty much, you would test on impact what speed that paddle was moving. if it was moving down, you would decrease the y speed of the ball by an amount that is directly or indirectly proportionate to the speed of the baddle. Same if it is moving up, except you would increase y speed.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: