Improved logic for CharacterBody collision recovery depth #52953
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.
This change generally makes character controller logic more consistent between 2D and 3D.
The main purpose is to allow 2D character controller to work without applying gravity when touching the ground.
In 3D it's already the case but it's now more consistent when parameters change.
Collision detection is also more flexible with different safe margin values.
Character body motion changes in 2D and 3D physics servers:
-Recovery only for depth > min contact depth to help with collision detection consistency (rest info could be lost if recovery was more than min contact depth, which is the threshold for detecting rest info)
-Adaptive min contact depth based on margin, instead of physics space parameter (this is following up from #45259 (comment))
Extra CharacterBody changes:
-2D: apply changes made in 3D for stop on slope and floor snap that help fixing some jittering cases
-2D: default floor snap is now 1.0 instead of 0.0 (in order to match the default 3D settings with snap enabled)
-3D: fix minor inconsistencies in stop on slope and floor snap logic
Tested in multiple use cases, no regression found in usual test cases from main test projects and previous issues.
Main test projects:
2D and 3D character controller tests from physics test demos, using 4.0 port from this PR:
Convert physics test projects to 4.0 godot-demo-projects#638
@fabriceci's 2D platformer test scene:
https://github.com/fabriceci/move_and_slide_4.0
@fabriceci's 3D platformer test scene:
https://github.com/fabriceci/3d-platform-test-for-godot4
(based on https://github.com/TokageItLab/3d-platform-test-for-godot4)
Fixes #37798 (fixes the tunneling with lower margin, but collision still has to be reduced in order to move in-between cells)
Fixes #36432
Helps with #24335 (fixes bumping against walls, still needs to use RigidDynamicBody2D to work better)