-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
When a KinematicBody is stuck, set the unsafe proportion to the minimum instead of zero. #38529
Conversation
@@ -989,7 +989,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co | |||
if (stuck) { | |||
|
|||
safe = 0; | |||
unsafe = 0; | |||
unsafe = 1.0 / (1 << 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should probably be a comment above this line to explain why this is done exactly. (Feel free to use GH-38529
as a reference to this pull request.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
// Set unsafe to the minimum after eight steps = 1/2^8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think code comments like these should be more about the why than the how. If I read that comment, I have no idea why it's being done this way 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you talking about why the unsafe is being set to the minimum, why the minimum is 1/2^8 or why 1/(1<<8) = 1/2^8?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this?
// When a KinematicBody is stuck, setting the unsafe proportion to the
// minimum instead of zero ensures that collision information is extracted
// even if the penetration causing the body to be stuck is less than the
// `test_motion_min_contact_depth`. See GH-38529 for details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm. I think that is excessive. Code shouldn't document why a change was made. It makes it look like setting the value to 1/2^8 is unusual, which it isn't. It is simply the value that unsafe would have been set to if this loop had been allowed to run:
godot/servers/physics_2d/space_2d_sw.cpp
Line 948 in e253451
for (int k = 0; k < 8; k++) { //steps should be customizable.. |
@@ -900,7 +900,7 @@ bool Space3DSW::test_body_motion(Body3DSW *p_body, const Transform &p_from, cons | |||
if (stuck) { | |||
|
|||
safe = 0; | |||
unsafe = 0; | |||
unsafe = 1.0 / (1 << 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
instead of zero. This ensures that collision information is extracted, in the direction of motion and ensures that a collision is reported.
Hi guys, just want to know if this one is going to be merged. |
Just a few pointers for good git commit messages, that's a good place for an extended 'why'
|
Superseded by #52953. |
When a
KinematicBody
is stuck, setting the unsafe proportion to the minimum instead of zero, ensures that collision information is extracted even if the penetration causing the body to be stuck is less than thetest_motion_min_contact_depth
. More importantly, this ensures that a collision is reported and doesn't allow the body to tunnel. Furthermore, it also ensures that the collision information is extracted from theCollisionShape
in the direction of motion not theCollisionShape
that happens to be closest or first.Note: The minimum is 1/2^8 because there are (an arbitrary) eight steps in the binary search.
Fixes #37798.
PS See my comment in #37798 for a more in depth analysis.