Repository navigation
fix: Refresh the cached hitbox centers of the QuadTree broadphase - #4248
Open
Yasser-Ameur wants to merge 1 commit into
Open
Yasser-Ameur wants to merge 1 commit into
Yasser-Ameur wants to merge 1 commit into
Conversation
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
marked this pull request as ready for review
November 26, 2026 11:35
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
With
HasQuadTreeCollisionDetectionandminimumDistanceset, 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.QuadTreeBroadphasecompares the live center of the active hitbox with a cached center of the other one.updateTransformis 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 firstaddwas kept for good and the moved hitbox was still measured from where it was added.updateTransformnow 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.dartcompare 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 onmainand pass here.Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues
Closes #4247