-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Ensure inherited default parameter is not redefined #49457
Conversation
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.
Thanks for catching the discrepancy. It would make more sense though to change PhysicsServer2D to use 0.08 as well, since it's the default value that is used for 2D.
Concerning #45361:
We've already discussed #45361 in a PR meeting, and the conclusion was that 0.001 is way too small to be the default value for 2D (it's 1/1000th of a pixel). Again as discussed, a welcome change would be to make test_motion_min_contact_depth
adapt to the margin instead of being a fixed value, so users can lower the margin if needed without breaking the motion algorithm.
This is off-topic, but for the record:
I've not seen any reasoning or data to support this assertion. Remember, a value of 0.08 is big enough to cause the visible jitter seen in #45259. 0.001 is the value currently used in 3D, and it's the value 2D was originally designed with. It's also only a default value, so a user can increase it if required.
#45361 also addresses the problem with reducing the margin breaking the motion algorithm seen in #36432. Note: Ultimately, the real problem is Godot physics' use of the safe margin. As described here, currently, to prevent collisions caused by numerical imprecision, Godot physics uses the safe margin to push the body away from other shapes before attempting the motion. The problem arises when this push is not cancelled by the subsequent motion. Note that even a value of 0.001 in 3D is sufficient to cause noticeable jitter as shown here (Figure 3). Personally, I think, instead of pushing the body away using a safe margin, Godot should have a tolerance during the motion; and a correction after the motion to address the penetration caused by numerical imprecision, similar to the way done in Bullet physics. |
@madmiraal The process behind body motion won't be entirely changed based on your personal preferences. I can be convinced otherwise, but it would be based on fixing issues that can't be fixed with the existing concept. This hasn't happened yet. If I will review #43616 at some point, but it will take some time to check and test. It's difficult to do so because that PR mixes changes in low-level physics algorithms, high-level motion process and a lot of code refactoring that makes it hard to identify what parts of the code are effective changes. Now on the current topic: At this point, the physics API just needs to be harmonized with the same default margin for 2D ( |
Superseded by #53280 (now the default margin is defined in PhysicsTestMotionParameters). |
As identified by lgtm, #48908 changed the default values for the inherited functions
body_test_motion()
andbody_test_ray_separation()
'sp_margin
values inphysics_server_2d_sw.h
to be different from the parent default values inphysics_server_2d.h
:godot/servers/physics_server_2d.h
Line 503 in f178e7a
godot/servers/physics_server_2d.h
Line 517 in f178e7a
"Inherited default parameters should not be redefined because this obscures the behavior of the code. Default values are statically bound and when they are redefined in dynamically bound function calls this reduces readability of the code, increasing the risk of introducing defects."[1]
This PR reverts that change so the inherited default values are once again the same as the parent's default values.
Note: The confusion comes from the fact that this function is called by
_body_test_motion()
(with an underscore) that passes a defined (non-default) value intobody_test_motion()
:godot/servers/physics_server_2d.cpp
Lines 514 to 520 in f178e7a
_body_test_motion()
p_margin
's default value is 0.08:godot/servers/physics_server_2d.h
Line 233 in f178e7a
And it's
_body_test_motion()
that is exposed asbody_test_motion()
:godot/servers/physics_server_2d.cpp
Line 646 in f178e7a
I've have previously suggested fixing this, so the values are all 0.001 by default as is the case in 3D physics: #45361 (and it's 3.x version: #45362). Perhaps we should reopen those PRs.