GLBasic forum

Main forum => GLBasic - en => Topic started by: Millerszone on 2010-Sep-14

Title: Collision can’t stop fast object [SOLVED]
Post by: Millerszone on 2010-Sep-14
When ball reaches high speeds (28+) it goes through the paddles. I tried both SPRCOLL and BOXCOL.
Are there any solutions besides making the paddle wider? or will a wider mask sprite of a paddle help?

Also, when the ball hits the very top or bottom back edge of the paddle, the ball goes inside the paddle
and moves through the paddle about half way and then comes out.

Here is the code for collision...

Code (glbasic) Select

// Ball and left paddle collision routine
      IF BOXCOLL(rpaddle_x, rpaddle_y, 14, 80, ball_x, ball_y, 14, 14)


Thank you.
Title: Re: Collision can’t stop fast object
Post by: ampos on 2010-Sep-14
If for speed you mean "pixel per frame" (you are moving the ball 28 pixel per frame), and the speed is wider than paddle, you can not get a hit.
Code (glbasic) Select

Dify=abs(yball-ypaddle)
if dify<(paddleheigh/2) and xball=>xpaddle then hit=true
Title: Re: Collision can’t stop fast object
Post by: Slydog on 2010-Sep-14
There are two ways to do this:

Title: Re: Collision can’t stop fast object
Post by: Scott_AW on 2010-Sep-14
You can loop it's movement per pixel in one frame and collision check each loop.
Title: Re: Collision can’t stop fast object
Post by: Millerszone on 2010-Sep-15
Thanks for the quick replies!

I stopped the ball from going inside of the paddle.

I still need a little help on making a loop to move the ball every pixel instead of 28.
If I move the ball a pixel at a time the ball moves to slow when LIMITFPS 60.
If I set LIMITFPS to -1, the ball and paddles goes to fast.

So this is where I need help.

Novak
Title: Re: Collision can’t stop fast object
Post by: ampos on 2010-Sep-15
Code (glbasic) Select
for n=1 to speed
   gosub moveball
next
showscreen
Title: Re: Collision can’t stop fast object
Post by: Slydog on 2010-Sep-15
Exactly what ampos wrote.  You don't move your ball 1 pixel per frame. 

With a fixed frame rate, that would make 'speed' useless, as it would always be moving at a speed of 1 pixel per frame.

With an unlimited frame rate (LIMITFPS = -1), you would have to figure out your own FPS logic to ensure your ball moved at the same speed for all users.  Each frame, you would calculate the distance moved by how much time has passed multiplied by your desired ball speed.  (and still have your original problem!)

Instead, you calculate your ball's new position in a loop and apply collision / direction changes each iteration of that loop.
So, if your speed is 28 (using ampos's code, that means 28 pixels per frame, not per second), each frame you would calculate your ball's new position 28 times, but only update it to the screen once, at the last position calculated.
Title: Re: Collision can’t stop fast object [solved]
Post by: Millerszone on 2010-Sep-16
Thanks again guys!  :booze:

The code by "ampos" worked perfect. I now get a speed of over 250!  :S

I am learning a lot from this forum. Soon will be making games for iPad.

Novak

Title: Re: Collision can’t stop fast object [SOLVED]
Post by: ampos on 2010-Sep-16
With so many royalties being paid from this forum, I am going to get rich without making anything!

:rtfm: