Point is inside object collision mask issue

I have seem to run into a strange behavior which I suspect is related to the “Test if a point is inside object collision mask” event. My game is emulating a physical puzzle where the player places various different sized pieces into a tray.

In the GDevelop simplified version attached, the “tray” is a sprite 280 x 280 px in size and is offset 20 px from the edge of the scene.
The tray is surrounded by a 5 px wide border (sprite) that will change color if a piece is placed on top of one of the border edges.
If a piece is completely inside the tray area, it will snap to the nearest (rounded) intersection when the mouse is released.
Each piece has the following Points defined based on the rectangle surrounding the object:
UL - upper left corner (0,0)
LR - lower right corner (depends on size of shape)
Origin - set to the CENTER of the piece
(in the full game, the shapes can be flipped and rotated, so the origin needs to be the center of the object. The UL and LR points effectively delineate the object rectangle for the “point inside object collision mask” test no matter how the piece is rotated or flipped).

Now that you have some background, the issue:
If the right edge of a piece is placed against the right most edge of the tray (in the example, the Shape.PointX(“LR”) = 300), OR if the bottom edge of a piece is placed against the bottom most edge of the tray (Shape.PointY(“LR”) = 300) the following event test fails:
If all these conditions are true:
Shape.PointX(“UL”); Shape.PointY(“UL”) is inside Tray
Shape.PointX(“LR”); Shape.PointY(“LR”) is inside Tray

if the shape is moved to 299, the snap works perfectly.

Note that the Left and Top borders work properly, and I’ve tried this in my full version with a rotated/flipped shape with the same results.

I’ve verified the HitBox for Tray is 280x280 and I’ve check the UL and LR points on each shape - all are correct.

I would really appreciate it if someone could tell me why this very narrow case is causing my code to malfunction. It may seem minor (it is only 1 px after all), but it is driving me crazy.

Thanks,
Art.

Example project can be downloaded from: Collision Mask Issue

Why don’t you want the snapping to work when the object is slightly outside boundaries? :thinking:
I replaced the AND by an OR, it’s much better to me :ok_hand: (and it fixes your issue)

Thanks, Gruk, but unfortunately that won’t work. I’m creating these puzzles on spec for the company that produces and sales my board games, and the owner is VERY particular that the snap only work when the shape is completely inside the board boundaries (which is why the borders change color if overlapped).

Ah, too bad… then make your tray one pixel bigger, without changing the boundaries. :blush:
(and adjust the z order of the tray)

As much as I would hate to do that, I may have to. I’m wondering if there is an problem with the way the “test if a point is inside object collision mask” is handling the sides of the rectangle where the vertices do not contain matching zero coordinates. For example:

X Y
0 0 Point 1
70 0 Point 2
70 70 Point 3
0 70 Point 4

Points 1 and 2 both have a zero in the Y coordinate and Points 1 and 4 have a zero in the X coordinate. Both of these lines work properly, however the line for points 2 and 3 do not have a matching zero pair and neither do points 3 and 4. Both of the lines (2-3 and 3-4) fail the test.

Whatever is causing the problem is subtle in nature but from my viewpoint, it seems to be a bug in the event.

Here’s some related info, see what you can make off it :sweat_smile:: PNPOLY - Point Inclusion in Polygon Test - WR Franklin (WRF)

Thanks Gruk, that article brings back some (not so) fond memories of doing an “in/out” exercise in an advanced statistics class back in my college days (some “ahem” years ago). After hand walking the FORTRAN code (yeah, I cut my teeth on FORTRAN back in the 70’s) on a few instances, I realized how a rounding issue can impact even a simple rectangle when dealing with an edge scenario. Looks like I will have to create a supplement test for the border conditions.
Thanks again,
Art.

1 Like