# Collision Detection with Rotated Texture2Ds?

Is there anything built into Monogame that handles collision detection of rotated Texture2D sprites (like this):

If there isn’t, I’m going to have to write it from scratch. But, if there is, I would hate to reinvent the wheel.

There is nothing built in

So short of using a physics library you will have to write it yourself.

Separating axis theorem is what you need to look up

If you only ever have to do rectangles, there’s another algorithm you can use. For each point in the rectangle, you can test to see if a point is inside another rectangle. You can do this by counting the number of times a line segment between that point and some point guaranteed to be outside (ie, -9999, -9999). If the count is odd then the point is inside.

Just wanting to let you know the options

I’m 68 years old. I learned that trick probably 25 years ago… and forgot it. But, yeah, that’s the way to do it.

1 Like

Oops, I forgot to add that you’d need to rotate your points first haha, but you knew what I meant I think it actually works for any concave polygon, right?

I think so. I can remember sitting in that class. I should probably go upstairs and see if I can find the textbook.

If you only need it for clustering purposes it may be simpler to just use regular circles for collision and accept some irregularities. Will be much faster and especially easier to code when it comes to closest point distances and such (and maybe even more failproof)

It’s not finding a collision alone but also how to react on it - circle/circle collisions are less complex than rect/rect collisions where orientation actually matters

1 Like

Nothing built in but you can implement GJK, see Winter's Blog
Or grab Farseer Physics GitHub - Genbox/VelcroPhysics: High performance 2D collision detection system with realistic physics responses. and call Collision.Collision.TestOverlap (see example at HernBlog )

Yeah, that’s my ‘fall back’ plan.