• Having trouble wrapping my head around 2D Polygon collision (Not Axis Aligned)
    11 replies, posted
So here's the gist of it: In the middle of writing a 2D Platformer in XNA, single scene so no need to worry about scrolling or anything here. Broad-phase I have perfected, as it's just checking a Rectangle.Intersects() with various entities, but it's the narrow-phase I have a problem with. My collision 'objects' are coordinate based, so they are essentially each a polygon made up of a list of x,y points. My entities colliding with these objects have Rectangle bounding boxes. I'm trying to wrap my head around how to get this working in a sane fashion, as I'd like for my platformer to be able to have sloping terrain that entities collide with properly, rather than just square collision. SAT was suggested to me as an option, but I'm not finding much on that for anything other than rectangles. Any thoughts guys? I don't necessarily need the code, just the steps to calculate collision direction and what Vector to apply to the entity to stop it moving into the collision object.
Maybe you want to take a look at Box2D
Really, I'd much prefer to learn this myself and write my own, it's much better for the learning experience than using a pre-made library.
Its open source, I said "take a look at" and not "start using it"
Ahah, you make a fair point. I shall go take a look at that now, cheers.
[QUOTE=Cue;38771686]So here's the gist of it: In the middle of writing a 2D Platformer in XNA, single scene so no need to worry about scrolling or anything here. Broad-phase I have perfected, as it's just checking a Rectangle.Intersects() with various entities, but it's the narrow-phase I have a problem with. My collision 'objects' are coordinate based, so they are essentially each a polygon made up of a list of x,y points. My entities colliding with these objects have Rectangle bounding boxes. I'm trying to wrap my head around how to get this working in a sane fashion, as I'd like for my platformer to be able to have sloping terrain that entities collide with properly, rather than just square collision. SAT was suggested to me as an option, but I'm not finding much on that for anything other than rectangles. Any thoughts guys? I don't necessarily need the code, just the steps to calculate collision direction and what Vector to apply to the entity to stop it moving into the collision object.[/QUOTE] SAT is mainly about collision [b]detection[/b], and I find it really strange how the info you find only handles rectangles. Can you give me a link to what you've found?
[QUOTE=ArgvCompany;38777000]SAT is mainly about collision [b]detection[/b], and I find it really strange how the info you find only handles rectangles. Can you give me a link to what you've found?[/QUOTE] I did find a couple of articles relating to polygons between when I posted this and now, but they were very wordy and rather than just breaking it down into a nice little list there was a lot of junk that made it quite hard to follow unless you already understand it to some extent. Incidentally, apparently for concave shapes I may run into problems with SAT, so I may have to rethink...
[QUOTE=Cue;38779371]I did find a couple of articles relating to polygons between when I posted this and now, but they were very wordy and rather than just breaking it down into a nice little list there was a lot of junk that made it quite hard to follow unless you already understand it to some extent. Incidentally, apparently for concave shapes I may run into problems with SAT, so I may have to rethink...[/QUOTE] Or you could just split up the shapes into convex ones. SAT is not that hard actually, you just need to understand things like vector projection.
[QUOTE=ArgvCompany;38779413]Or you could just split up the shapes into convex ones.[/QUOTE] Is there a good way to go about doing that on the fly rather than editing the level data though?
[QUOTE=Cue;38779429]Is there a good way to go about doing that on the fly rather than editing the level data though?[/QUOTE] I know there are algorithms for that, but unfortunately I have never needed them, and therefore I don't know the details of any.
I highly, highly suggest you read [URL=http://www.metanetsoftware.com/technique/tutorialA.html]this tutorial[/URL].
Oh wow, the people that made N.
Sorry, you need to Log In to post a reply to this thread.