So I've been working on a little game and in beginning I was simply using Slick and regular rectangles for collision detection. This worked fine for a while. Even with rotated shapes still generally worked. But then I had a bad guy that was 2x as long as he was wide. I tried to couple 2 rectangles to him but it was having issues. Then I ran into a problem with my "laser beam" which I was trying to use a super long rectangle(100 long x 1 wide)

Anyways, I realized I needed to learn how to better do collision detection. I kept seeing separating axis theorem and AABB(Axis Aligned Bounding Boxes) stuff. Most of the time it was either in other language code or abstract math.

I was frustrated.

I was always running into problems with built in polygons and other issues. Specifically when it came to rotating and whatnot.I decided to build a custom detection system from the ground up, that works for me.It may work for you. Its more complicated then a simple rectangular or distance check.

This is not yet optimized, but I tried to simplify it as much as I can for right now.

FYI, this currently supports ANY Convex Polygons.You can manually set it to any polygon you want, I just have it set to auto random polygons.

I plan to add more features/functions in other future versions/posts. If you see anything that could be simplified or optimized. Let me know. Typically i want it to keep it as simple/short as possible so others can modify it to work with their code.

Left click to toggle between the 2 bodies. 1 can push the other, whereas 1 resists movements.

You either are pushing or resisting toggle modes to demonstrate 2 separate principles.As you can see in the picture, the blue shape will show the minimal deflected position. Its not perfect but its a fairly good behavior.

Well technically, mine has the ability to skip the rest of checks in certain cases (i.e. if the first check is true x + w < x2, then it can return right away) in worst case scenario it should be just as fast as that method you post (which has to check all boundaries before returning true or false).

However... realistically, they are doing close to the same thing (also I didn't see a point in adding a check when I know that my rectangle bounds will always be above 0, not that having a check is costly) so the speed difference is very negligible.

Well technically, mine has the ability to skip the rest of checks in certain cases (i.e. if the first check is true x + w < x2, then it can return right away) in worst case scenario it should be just as fast as that method you post (which has to check all boundaries before returning true or false).

However... realistically, they are doing close to the same thing (also I didn't see a point in adding a check when I know that my rectangle bounds will always be above 0, not that having a check is costly) so the speed difference is very negligible.

Intersects2, your intersects. All the casting to int, I do for my intersect aswell.

Turns out yours is often slower, and more importantly incorrect.When I did [100][100] rects, one error came up. Here I use 500x500 and like 15 come up.Not that this much, but still incorrect sometimes.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org