HOME | DD

psykopath — Polygon-point collision FLA by

Published: 2007-12-22 13:15:59 +0000 UTC; Views: 1184; Favourites: 2; Downloads: 206
Redirect to original
Description Theres a lot of junk code in there for making the whole thing run, but all you really need from this is the function PointInPoly, and PolyCollide if you want.

The functions expect that the polygons are objects with a property 'pts' which is an array of points. The array should contain the same point at the start and the end.

Example:
mypolygon = { pts:new Array({x:10, y:10}, {x:50, y:50}, {x:25, y:75}, {x:10, y:10}) }

The rest of the code is for drawing the shapes and interacting with the menu thing, might be useful, maybe not.

Live example: [link]
Related content
Comments: 7

AGameAnx [2008-08-06 13:05:28 +0000 UTC]

Yeah well i didn't script for a really long time, sorry.

You should also do it with the penetration vector.
All you have to do is check for distance and angle between a vector between point1 of object1 and any point from object2 (v1) and a vector from same point from object1 to the next point on object1 (v2). If the angle between these vectors is > 0 (note, you can also use < 0 but then some things change) then they are penetrating.
Distance is only needed for returning the penetration v with angle of v2 - 90 (if you are checking the > 0 overthere then v2 angle + 90). Do this for each point on both objects, if any point has penetration with all the vectors this means objects are penetrating.
Make sure you return the smallest penetration vector as otherwise you might get unwanted results most of the times

Your array is acceptable for such collission detection but you'll have to make sure that you are moving your vectors in the right direction...

I was going to use such detection method for my a couple of my new projects but i didn't ever finish nor try this method out, just used boxes and circles specific detection methods and that's it (i was including object reactions but i always stopped at rotation result of applied force)

This comment makes me want to work on it again

👍: 0 ⏩: 1

psykopath In reply to AGameAnx [2008-08-06 22:49:52 +0000 UTC]

Interesting, I've been trying to do that with some other stuff lately but could never really understand the explanations on the internets.

👍: 0 ⏩: 1

AGameAnx In reply to psykopath [2008-08-07 05:47:59 +0000 UTC]

Yea me too, i thought of this myself, they were usually using projections and other stuff which also works but is harder to do imo, i'm working on that again now as my interest for it is back because of all these comments

👍: 0 ⏩: 1

psykopath In reply to AGameAnx [2008-08-07 22:54:02 +0000 UTC]

Dunno if you've seen this but there's some easy projection stuff in this [link]

👍: 0 ⏩: 1

AGameAnx In reply to psykopath [2008-08-08 13:44:19 +0000 UTC]

Nah i didn't see it, i'm new in DA Great tutorial there and i know about projection method yet i still don't want to use it as i was pretty much at the main point where i just needed to do the projection and i couldn't do it backthen... Some sides were working properly some not, i just got lazy to fix it and now i want to try this method out

👍: 0 ⏩: 0

AGameAnx [2008-08-05 14:45:57 +0000 UTC]

Nice but you should return a penetration vector, that would be something really useful! I think AS2 can check if any object overlaps another anyway

👍: 0 ⏩: 1

psykopath In reply to AGameAnx [2008-08-05 22:37:37 +0000 UTC]

No, if AS2 could check for two arbitrarily shaped objects then this would be completely pointless for me to make. It can check for a movieclip and a point, or the bounding rectangles of two movieclips.

👍: 0 ⏩: 0