HaxePunk icon indicating copy to clipboard operation
HaxePunk copied to clipboard

Fix Grid collisions with Hitbox

Open SunShiranui opened this issue 7 years ago • 3 comments

I've noticed some unexpected behaviour when using Grid - hitboxes colliding with a wrong offset. This change seems to fix the issue, so I thought I'd send it over for review.

It looks like collideMask might have a similar mistake - but I haven't tested it.

SunShiranui avatar Apr 20 '18 11:04 SunShiranui

I don't doubt there's an issue here, but the original makes more sense to me than the patch: the original is (mask X - entity X) - (other mask X - other entity X) which gives you the difference in compensated positions; the new one flips it to (mask X - entity X) + other mask X + other entity X.

bendmorris avatar Apr 25 '18 16:04 bendmorris

Isn't the original equivalent to: (otherEntityX - otherMaskX) - (EntityX + MaskX)?

If we want the difference in positions, shouldn't we be doing this instead: (otherEntityX + otherMaskX) - (EntityX + MaskX)

I apologize if there's something I'm missing.

SunShiranui avatar Apr 25 '18 17:04 SunShiranui

I think you're right about what we want, I need to look more closely at this logic. However:

_rect.x = other._parent.x - other._x - _parent.x + _x;

is the same as (just moving them around):

_rect.x = _x - _parent.x - other._x + other._parent.x;

which is the same as:

_rect.x = (_x - _parent.x) - (other._x - other._parent.x);

So it's consistent now, even if it's doing the wrong thing, and flipping a sign is probably not the right fix.

bendmorris avatar Apr 25 '18 21:04 bendmorris