Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved logic for CharacterBody collision recovery depth #52953

Merged

Conversation

pouleyKetchoupp
Copy link
Contributor

@pouleyKetchoupp pouleyKetchoupp commented Sep 22, 2021

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:


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)

scene/2d/physics_body_2d.cpp Outdated Show resolved Hide resolved
scene/2d/physics_body_2d.cpp Outdated Show resolved Hide resolved
scene/3d/physics_body_3d.cpp Show resolved Hide resolved
servers/physics_3d/space_3d_sw.cpp Show resolved Hide resolved
Allows 2D character controller to work without applying gravity when
touching the ground (also more safely in 3D), and collision detection
is more flexible with different safe margin values.

Character body motion changes in 2D and 3D:
-Recovery only for depth > min contact depth to help with collision
detection consistency (rest info could be lost if recovery was too much)
-Adaptive min contact depth (based on margin) instead of space parameter

Extra CharacterBody changes:
-2D: apply changes made in 3D for stop on slope and floor snap that help
fixing some jittering cases
-3D: fix minor inconsistencies in stop on slope and floor snap logic
@pouleyKetchoupp pouleyKetchoupp force-pushed the fix-collision-recovery-depth branch from ccd483b to bf523a2 Compare September 27, 2021 22:32
@akien-mga akien-mga merged commit 60988a0 into godotengine:master Sep 28, 2021
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants