# collision of ball and rectangle

This topic is 2822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'd like to figure out how to deal with collision similar to arcanoid game only where the paddle can have slope different than 0.

An image is attached of what I'm trying to explain, and even though the paddle seems to be at 45 degree angle, I'd like it to be at any angle.
[attachment=6925:image.jpg]

Ultimately I'd like to know how to calculate the trajectory after impact, but any help is greatly appreciated - including how to even detect that there was a collision.

##### Share on other sites
http://mathworld.wol...tersection.html

testing against the front of the paddle should be sufficient, unless the ball moves really fast in which case you could:
*split up the movement into smaller parts and make more tests.
or
*Check if the line from the balls old to new position intersects with the paddle (google line-line intersection)
or
*Check what side of the line the old and new position of the ball is and if it changes side without triggering a colission do either of the above.
http://www.gamedev.n...ine-a-point-is/

To get the basic trajectory after impact you could:

1) Get the paddles Normal (a vector pointing forward or out from the paddle)
2) Check the angle between the balls movement vector and the paddles normal
3) Reflect the ball back on the other side of the normal. (So if it goes in towards the paddle at an angle of 20 degrees to the normal you send it out at -20 degrees from the normal) (For normal breakout you tend to adjust the reflection angle based on the distance from the center of the paddle instead, but in your case that shouldn't be needed as the player can control the angle the ball hits from instead, but you could try adjusting based on distance from center aswell and see if that provides better gameplay)

##### Share on other sites

I'd like to figure out how to deal with collision similar to arcanoid game only where the paddle can have slope different than 0.

An image is attached of what I'm trying to explain, and even though the paddle seems to be at 45 degree angle, I'd like it to be at any angle.
[attachment=6925:image.jpg]

Ultimately I'd like to know how to calculate the trajectory after impact, but any help is greatly appreciated - including how to even detect that there was a collision.

You need a circle vs OBB routine - I describe this in my article on collision detection:

http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/

Cheers, Paul.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 21
• 23
• 11
• 25