Collision can’t stop fast object [SOLVED]

Previous topic - Next topic

Millerszone

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.
Hardware: iMac 27", MacBook Air, PC 3.5Ghz Quad
Developing Tools: GLBasic SDK, Gideros Studio, PureBasic
Developing for: iOS, Android, Windows, OS X, webOS, HTML5

ampos

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

Slydog

There are two ways to do this:


  • Instead of checking once at 28 pixels, each frame you have to make a loop from 1 to 'speed' and check for a collision at each of those locations, then you will also know the exact pixel where the collision occurs.  More time consuming, but accurate.

  • Use a ray casting routine that casts a virtual ray in the direction of the ball and returns if it hits anything within a certain distance.  There is a 3D version of this called 'X_COLLISIONRAY()', but I'm not sure if there is any 2D version anywhere.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Scott_AW

You can loop it's movement per pixel in one frame and collision check each loop.
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/

Millerszone

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
Hardware: iMac 27", MacBook Air, PC 3.5Ghz Quad
Developing Tools: GLBasic SDK, Gideros Studio, PureBasic
Developing for: iOS, Android, Windows, OS X, webOS, HTML5

ampos

Code (glbasic) Select
for n=1 to speed
   gosub moveball
next
showscreen

Slydog

#6
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.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Millerszone

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

Hardware: iMac 27", MacBook Air, PC 3.5Ghz Quad
Developing Tools: GLBasic SDK, Gideros Studio, PureBasic
Developing for: iOS, Android, Windows, OS X, webOS, HTML5

ampos

With so many royalties being paid from this forum, I am going to get rich without making anything!

:rtfm: