DRiFTy
DRiFTy

Reputation: 11369

Determine Which Side of Rectangle Was Hit

So I have a circle moving towards a rectangle on screen in my Android game. Each has a bounding box with left, top, right, bottom values that match their screen coordinates. I determine if there was a collision using the RectF.intersects(RectF one, RectF two) method. Now my problem is to determine which side the collision occurs on. I have done some searching around and every answer just confuses me. Does anyone have any ideas?

Upvotes: 1

Views: 1328

Answers (1)

edthethird
edthethird

Reputation: 6263

wait, you are drawing a circle and a rect, and you checking intersections on two rects?

Why not draw a circle and a rect on the canvas, and measure the distance between each edge of the rect and the center of the circle. If any of those 4 distances < radius of circle, you'll know which edge was hit.

Upvotes: 2

Related Questions