Skip to content

fix: Refresh the cached hitbox centers of the QuadTree broadphase - #4248

Open
Yasser-Ameur wants to merge 1 commit into
flame-engine:mainfrom
Yasser-Ameur:fix/quadtree-centers
Open

Yasser-Ameur wants to merge 1 commit into
flame-engine:mainfrom
Yasser-Ameur:fix/quadtree-centers

Conversation

@Yasser-Ameur

Copy link
Copy Markdown
Contributor

Description

With HasQuadTreeCollisionDetection and minimumDistance set, a hitbox that moved after it was added could stop colliding (#4247). A passive platform added at (500, 500) and moved onto an active player at (0, 0) never produced a collision.

QuadTreeBroadphase compares the live center of the active hitbox with a cached center of the other one. updateTransform is the place where that cache is meant to be refreshed when a hitbox moves, but it called _cacheCenterOfHitbox, which only writes when no entry exists. So the center from the first add was kept for good and the moved hitbox was still measured from where it was added.

updateTransform now writes the new center. It only runs for hitboxes whose transform (or an ancestor's) changed, so the cache still saves the work for everything that stays still.

The new tests in collision_callback_test.dart compare the reported collisions with a plain rectangle overlap check after each move, including a hitbox that goes out of range and comes back. They fail on main and pass here.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • [-] I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • [-] I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Closes #4247

With HasQuadTreeCollisionDetection and minimumDistance set, a hitbox
that moved after it was added stopped colliding. A passive platform
added at (500, 500) and moved onto an active player at (10, 10) never
produced a collision.

QuadTreeBroadphase compares the live center of the active hitbox with a
cached center of the other one. updateTransform is meant to refresh that
cache when a hitbox moves, but it called _cacheCenterOfHitbox, which only
writes when no entry exists, so the center from the first add was kept
for good. Write the new center in updateTransform instead.
@Yasser-Ameur
Yasser-Ameur marked this pull request as ready for review November 26, 2026 11:35

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QuadTree collision detection with minimumDistance misses hitboxes that moved

1 participant