We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › collision example
Page Index Toggle Pages: 1
collision example (Read 633 times)
collision example
Nov 14th, 2006, 4:28pm
 
hi

sorry for following simple question, i'm sure there is an easy solution!

in the collision example:

http://processing.org/learning/examples/collision.html

i would like to increase the speed of the ball, i did this here:

Code:
ball_x += ball_dir * 10.0; // change here
ball_y += dy;
if(ball_x > width+ball_size) {
ball_x = -width/2 - ball_size;
ball_y = random(0, height);
dy = 0;
}


but now the ball doesn't collide with the paddle or walls. what am i doing wrong?

thanks
Re: collision example
Reply #1 - Nov 18th, 2006, 3:35pm
 
It seems that by changing the constant to 10.0, the steps the ball takes in figuring out if it hit the paddle each draw cycle are too large. The paddle itself is only 5px wide

Consider: if the ball is at px=300, and paddle is from 303 to 308, for example, the ball will simply seem to pass through the paddle, as it's next position is 310, which isn't on the paddle, so the collision test fails.

Try either lowering the constant, or increasing the size of the paddle. That should do the trick. You just have to make sure that there's no chance that between two different draw cycles, the ball totally bypasses the paddle.
Page Index Toggle Pages: 1