   Yet another collision question
  I'm creating a simple breakout clone in C# and I need to get some better collision detection.At the moment the ball only respond to hitting the top of the paddle and then bounce off in the oppsite y direction, basicly what I want to archive is make it more sensitive to where on the paddle it hits, for example if it hit's the side of the paddle it should shift the x direction but not the y direction.http://dndesign.dk/seph/box.jpgI'm currently using the following code:// Has the ball hit the paddle?if (Position.X + Width >= Paddle.Left && Position.X <= Paddle.Right && Position.Y + Height <= Paddle.Bottom && Position.Y + Height >= Paddle.Top){// Then reverse the vertical direction.DirectionY = -1;// And change the Horisontal speed depending on where the ball hit the paddle.int PaddleHit = (Paddle.X + Paddle.Width / 2) - (Position.X + Width / 2);// PaddleHit has a value between -(Paddle.Width / 2) og Paddle.Width / 2 where 0 is the middle.if (PaddleHit >= 0){// <-DirectionX = -1;}else{// ->DirectionX = 1;}MovementSpeedX = Math.Abs(PaddleHit / Sensetivity) + 1;}
  First of all, you'll have to check the direction the ball is moving.  If you don't, your ball will potentially start bouncing back and forth within a paddle.  When the ball is moving to the left, just check collisions with the left player.  When the ball is moving to the right, check collisions with the right player.  When there is a collision, all you have to do is reverse the X direction of the ball.  Looking at your code, it should look something like DirectX *= -1; .   ;  What I would do is this.1) Test Sphere to left Line Segment- If intersection, solve for smallest time it intersected2) Test Sphere to upper Line Segment- If intersection, solve for smallest time it intersected3) If no inersection in step #1 - Test Sphere to right Line Segment- If intersection, solve for smallest time it intersected.When you have an intersection, you want to find out where it intersected first. Say it intersected with the top line and left line. Compare the intersection times and the one that is smaller, determine its delta time and move it back in the opposite direction it came from * delta time.For example:- Direction the ball was traveling is <5,-5>, normalize this so it now equals Direction<.747,-.747>.- Current time is 10 seconds, intersection time is 9.5, so the delta time is 0.5 seconds.- Move the ball back (negate Direction to <-.747, .747>) by its negative direction times delta time.- Position = CurrentPosition + <-.747, .747> * 0.5Now you've move the ball to its current intersection point, you just need to reflect it correctly. If it intersected with left or right, negate the x component of its velocity, otherwise negate the y component.The only hard part is doing a line segment to sphere intersection testDave- If you need anything clarified just ask!;  I think you got it wrong, I'm not doing a pong game, I'm doing breakouthttp://dndesign.dk/seph/breakout.jpgObviously I need this for the paddle and the bricks to ensure the ball behaves as expected.The problem with the hit detection I'm using now is that it only checks if the ball hits the area the paddle is in, not which side, so if it hits it bounces back up.For the bricks I'll need to know if it hits the side, and since the paddle and the bricks is the same shape I might as well apply the same hit detection to the paddle.@Ph33r, That looks like the thing I want, now to decipher that page...   