Tolerate floating-point drift at AABB contacts - #135
Draft
aibengineering wants to merge 4 commits into
Draft
Conversation
aibengineering
force-pushed
the
codex/aabb-contact-epsilon
branch
from
July 24, 2026 01:54
e7eb35d to
4e9bd8e
Compare
|
this PR would also address PrismarineJS/mineflayer#3913 :) |
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.
Summary
Fix AABB collision offsets when two faces that should be touching differ only by floating-point rounding.
The change adds a symmetric
1e-7metre contact tolerance tocomputeOffsetX,computeOffsetY, andcomputeOffsetZ. It does not change the player hitbox or scale.How we found it
We were reproducing a Mineflayer Pathfinder failure in Minecraft 1.21.4 where a bot repeatedly got stuck while climbing a compact staircase with a U-turn.
Tracing the movement showed that Pathfinder selected a valid route and the controller issued the expected input. The failure occurred later, during the local collision sweep: physics allowed the player to move a tiny distance into the block, the server corrected the position, and the controller retried the same jump.
At the block face where the bot stalled, the player AABB was reconstructed as:
The two faces should meet at
x = 4, but the negative-X collision check used an exact comparison:That becomes
3.9999999999999996 >= 4, so contact is missed.We confirmed that this was a rounding issue by trying several player half-widths. Tiny changes caused the same course to alternate between passing and failing:
0.30025passed 4/4 runs, while the larger0.30050failed 4/4;0.301happened to pass. Because the result was non-monotonic, there was no geometrically “correct” replacement width—the width changes were only changing how the face coordinates rounded.What changed
CONTACT_EPSILONof1e-7metres.intersectssemantics unchanged.The player AABB is not expanded. Real gaps retain their exact clearance, overlap beyond the tolerance keeps the existing behavior, and movement away from contact remains unrestricted.
Tests
This PR adds
test/aabb.test.jswith 19 AABB collision-offset tests. They cover every axis and both movement directions, including:The complete repository test suite passes: 38 tests total (19 new AABB tests and 19 existing tests).
External movement tests
Separately from this repository's unit tests, we installed the patched package into Mineflayer Pathfinder and ran a bot through several movement courses in Minecraft Java 1.21.4.
playerHalfWidth = 0.3andplayerHeight = 1.8, with no Pathfinder stuck resets or damage.These movement tests are external to this repository and are not part of the
prismarine-physicstest suite.Related reports
This change fixes the exact-contact rounding failure without requiring changes to player scale, half-width, or height.