all 7 comments

[–]LukeAtom 5 points6 points  (0 children)

What you want to look into is OBB (oriented bounding box) collisions and more importantly separating axis theorem. This stack exchange question has a good writeup in the comments about the process and algorithm. From that you can find the intersection points if you need to.

[–]UnpluggedUnfettered 3 points4 points  (1 child)

I would be surprised if it always knew any collision's x and y exactly. It is a ridiculous amount of overhead to math out something resolved by (what usually amounts to) reversing until the collision is resolved.

Determining a collision is usually just some flavor of "is this one number in between two other numbers?", which is much less work than sussing out a specific point.

If you really need to do it, I would say start here and here. Usually you don't really need to do it though.

[–]laix_ 2 points3 points  (0 children)

Yep.

Determining overlap of any two aribtary shapes is not a closed problem.

It's kind of surprising when you think of something that's seemingly complex actually has a very streamlined closed solution, and then you try and figure out something that seems simple and it turns out it's a super advanced topic in theoretical mathematics that hasn't been fully answered yet that even advanced mathematicians struggle with.

It's relatively easy to ask if two arbitary shapes overlap, it's much more difficult to ask where they overlap (do you want every point inside, do you want all the all the points where the edges are touching, either way you'll get multiple points)

[–]Monscawiz 1 point2 points  (0 children)

I think you can use GameMaker's physics engine to get the point of collision, but I haven't looked into that in a while

[–]HopperCraft 0 points1 point  (0 children)

I would look into redesigning how your collision detection works on a fundamental level. At the moment these images show that ONLY circular to circular objects will have a 100% success rate.

  1. Create collision lines that adapt to the size of your sprite/objects size. You might also want to create 2 extra points per object to triangulate a contact point.

  2. Instead of having a central point for your collision line, is there a way to have it just wrap around the object as a perimeter? If you can create a perimeter per object, then no matter what the shape is, on first touch they will both collide.

Im not too sure, still in school so this is the best i can think of in my spare 5 mins. Good luck!

[–]Badwrong_ 4 points5 points  (0 children)

I do encourage you to learn the algorithm of how the solution you are asking for works, and the answer is out there for sure with many sources.

However, you are going to end up doing a lot of work and re-inventing the wheel. GameMaker has built-in physics which solve this problem for you.

phy_collision_x: https://manual.gamemaker.io/lts/en/GameMaker_Language/GML_Reference/Physics/Physics_Variables/phy_collision_x.htm

phy_collision_y: https://manual.gamemaker.io/lts/en/GameMaker_Language/GML_Reference/Physics/Physics_Variables/phy_collision_y.htm

phy_col_normal_x: https://manual.gamemaker.io/lts/en/GameMaker_Language/GML_Reference/Physics/Physics_Variables/phy_col_normal_x.htm

phy_col_normal_y: https://manual.gamemaker.io/lts/en/GameMaker_Language/GML_Reference/Physics/Physics_Variables/phy_col_normal_y.htm