Jump to content
  • Advertisement
Sign in to follow this  
abeylin

collision of ball and rectangle

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!