collision of ball and rectangle

Started by
1 comment, last by wildbunny 12 years, 2 months ago
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.

http://www.mildspring.com - developing android games

Advertisement
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)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

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.

This topic is closed to new replies.

Advertisement