Fix test_body_motion recovery and rest info #46148
Merged
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 makes
test_body_motion
more reliable when the kinematic body recovers from being stuck.Fixes #45259
Fixes #45971
Fixes #46134
Detailed changes:
When recovery occurs, the rest information is generated, in order to make sure collision results from
test_move
,move_and_collide
andmove_and_slide
are consistent and return a collision in case of overlap.See regression Collision detection unreliable with KinematicBody2D inside CollisionPolygon2D #45971
The new calculation for recovery vector makes sure the recovery is never more than the overlap depth between shapes.
This can help with cases where the kinematic body overlaps with several shapes.
Recovery is made iteratively, without forcing a full overlap at each step. This helps with getting proper rest information when recovery occurs (previous point).
Based on Fix multiple issues with test_body_motion() and test_body_ray_separation(). #35945 (comment)
One Way Collision:
When attempting motion, contact direction is checked against motion before skipping in order to solve cases where kinematic bodies can sink into one-way collision shapes.
Rest info now sets max contact depth in order to properly handle one-way collision, the same way it's done during the recovery step.
Low speed motion is now handled in the rest info, by never setting
min_allowed_depth
lower than motion length.Separation is always applied with full margin, otherwise contact is lost when low speed motion occurs right after higher speed motion.
See regression Regression in KinematicBody2D.move_and_slide where slide is instable and body sometimes bounce up for few frames #46134
Similar changes are applied to 3D in order to make 2D and 3D consistent.
List of tested cases (in addition to the fixed regressions):
Note: most tests have been done on the 3.2 version, because many of the test projects haven't been ported to 4.0.
Physics tests from Godot demos:
https://github.com/godotengine/godot-demo-projects/tree/master/2d/physics_tests
Functional Tests/Character - Slopes: no regression with KinematicBody2D moving on slopes.
Functional Tests/Character - Tilemap: no regression with KinematicBody2D jumping through one-way collision tiles.
Functional Tests/One Way Collision: no regression with one-way collision at different angles.
MRP from issues fixed by PR Fix multiple issues with one-way collisions #42574:
KinematicBody2d move_and_slide function, The value returned by a collision at a particular location is not normal #25967
Shapes without flat bottom can't jump on a rising moving platform #34242
KinematicBody2D when pushed falls if it touches two one way collision static bodies. #35776
Two or more KinematicBody2D on top of another KinematicBody2D makes the below one to move #40006
The test_move() function may not be behaving properly, when rotating #42175
KinematicBody2D hugs corners when using move_and_slide() #43012
KinematicBody2D can fall through sloped one way polygons at certain points #43266
No regression spotted.
Extra cases fixed by PR Fix multiple issues with one-way collisions #42574:
Fix multiple issues with one-way collisions #42574 (comment)
Fix multiple issues with one-way collisions #42574 (comment)
Fix multiple issues with one-way collisions #42574 (comment)
No regression spotted.
Tests for 3D using MRP from PR Fix multiple issues with test_body_motion() and test_body_ray_separation(). #35945:
Fix multiple issues with test_body_motion() and test_body_ray_separation(). #35945 (comment)
Jittering still not visible when using Godot Physics.
Other tests for 3D:
[Bullet] KinematicBody3D: is_on_floor() can become false when moving against a wall #33833
Floor detection still consistent in corners.