Page 1 of 1

Help with Collision Detection

PostPosted: Nov 27, 2003 @ 12:50am
by markhsch
Ok, I give up. This should be so easy, but for the life of me can't figure out the best method. Basically, think of a single stationary block and a bouncing ball (ala Araknoids). I need to determine if the ball should reverse Y direction if it hits on the top or reverse X direction if it hits the block on the side. My basic game loop is:

1) Render ball
2) Animate ball (applies x and y speed to x&y vals)
3) Go through blocks and see if ball has collided

It's step 3 that is messing up. I seem to find collisions from top or bottom find (ptIntersect.y is equal to the top or bottom coord of block), but the side collision is giving me problems.

Here are some images.

1) This shows the CollisionMask sample with graphics changed to look like what I am using. This is the ball hitting the block from the top. Note that the ball overlaps the block. This is because the Y speed is set to something like 5 pixels so it has the possibility of overlapping by at most 4 pixels (I move it to the top edge if a collision is detected, but collision detection occurs with overlapping).

Image

2) This shows the same example with the ball coming from the right. Things to notice: the SpriteCollision Y value is the same in 2nd image as first so I can't use that to determine which direction I should bounce the ball.

Image

Well, I hope this post made sense. Any help I can get I'd really appreciate.

Oh, and no, the game I am working on is not another breakout/araknoid clone. Something entirely different.

-Mark

PostPosted: Nov 27, 2003 @ 12:56am
by ppcStudios
Is it possible for you to use the direction vector of the ball's motion to determine the resulting direction after the collision?

Clarification

PostPosted: Nov 27, 2003 @ 12:59am
by markhsch

Code and Binaries

PostPosted: Nov 27, 2003 @ 1:04am
by markhsch

Whoops

PostPosted: Nov 27, 2003 @ 1:07am
by markhsch

PostPosted: Nov 27, 2003 @ 4:17am
by ppcStudios

PostPosted: Nov 27, 2003 @ 11:36pm
by mlepage
This issue is called "tunneling" if you wish to search for it.

PostPosted: Nov 29, 2003 @ 2:08am
by 8bit