You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
QuadTree collision detection with minimumDistance misses hitboxes that moved #4247
With HasQuadTreeCollisionDetection and minimumDistance set, a hitbox that was added far away and then moves next to another hitbox never collides with it.
What do you expect?
The same collisions as without minimumDistance: once the two hitboxes overlap, onCollisionStart fires on both.
How can we reproduce this?
classMyGameextendsFlameGamewithHasQuadTreeCollisionDetection {
@overrideFuture<void> onLoad() async {
initializeCollisionDetection(
mapDimensions:constRect.fromLTWH(0, 0, 1000, 1000),
minimumDistance:50,
);
}
}
// player: active RectangleHitbox, position (0, 0), size 10// platform: passive RectangleHitbox, position (500, 500), size 10await game.ensureAddAll([player, platform]);
game.update(0);
platform.position =Vector2.all(5); // now overlaps the player
game.update(0);
// expected: player.onCollisionStart called once// actual: never called, however long the two stay overlapped
If the platform is added in range and then moved, it works, so it depends on where the hitbox was when it was first added.
What steps should take to fix this?
QuadTreeBroadphase keeps a cached center per hitbox for the minimumDistance check. updateTransform calls _cacheCenterOfHitbox, which only writes when there is no entry yet, so the center from the first add is kept and the moved hitbox is still measured from its old position. Writing the new center in updateTransform fixes it. I have that change with tests and will open a PR.
Activity