# Circle to rectangle collisions? 2-D game

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

## Recommended Posts

Hey all. I have this situation of wanting lasers to hit the player in my game. The player's hitbox is a circle. Lasers would be best represented as a rectangle. They can be thick lines, hence the rectangle approach. Lasers could also be going out of something diagonally on-screen, but always in a straight line. So... is there an easy way to see if said circle overlaps a rectangle of this nature? Also out of curiosity, maybe a parallelogram too? I'm wondering if I should have that shape for lasers instead... Thanks.

##### Share on other sites
You could do 4 circle line intersection tests that way you could do parallelograms as well. To detect a circle line intersection you only have to check the closest point from the circles origin to the line and check if that lies within the circle radius.

 If your rectangles are actually big enough to contain the circle you need to check if the circle origin lies on the 'inside' of each line as well.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634140
• Total Posts
3015760
×