#intersect_polygons returning wierd resulting shape

11 messages · Page 1 of 1 (latest)

tepid oasis
#

I am having an issue with the attached code. I am trying to slice and avacodo (represented as a Polygon2D) in half using the Geometry2D functions. intersect_polygons seems to be returning the wrong resulting shape.

the second screenshot is at runtime. the top red line (it is actually a line with enough points to make a box shape that extends to the bottom of the screen, you can see the red line at the bottom showing that) is where the cut is supposed to happen. As you can see, it is not preforming the cut in that location.

The third picture is in editor, just showing the bounds of the polygon2D for reference. The UV matches the polygon.

Would greatly appreciate it if anyone has clues as to why its not intersecting on the red line.

#

here is another screenshot to show what happens when the cut line is further down. It is a consistant offset distance from the line, still don't know the reason why.

cold ibex
#

I did some testing on my own and it looks like the intersect_polygons function doesnt take into consideration the transform of the polygons when intersecting them, which seems weird to me

#

from what I can tell, it takes the polygons, moves both of their positions to 0,0 and then intersects them

#

You can see in this screenshot that I have both polygons transform set to 0,0

#

here you can see the shape they make when the intersect

#

now if I try to move the two shapes and run everything again, you can see that it ignores their transform and just treats them as though they were still both at 0,0

#

So, i'm guessing you probably have to add some offset equal to the transform of the object to the points that make up the object's polygon in order for it to work properly

cold ibex
#

If you run the project, you can move the square using WASD or the Arrow Keys and you'll see the green intersection update