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.
Objective
Logic related to mass properties is currently a bit scattered around (
PreparePlugin
,ColliderBackendPlugin
...), and there is also no way to opt out of automatic updating of mass properties. It would be nice to encapsulate this logic inside a single plugin, especially as we rework mass properties (#499) and add more APIs and functionality for working with mass.This also contributes to the goal of removing
PreparePlugin
, which is currently full of various miscallaneous and unrelated logic.Solution
Add a
MassPropertyPlugin
. It updates mass properties of rigid bodies when colliders are added or removed, or when theirColliderMassProperties
are updated. It also logs warnings for invalid mass properties, and updatesGlobalAngularInertia
.Previously, the logic for updating mass properties based on
ColliderMassProperties
changes was heavily tied to theColliderMassProperties
update logic inColliderBackendPlugin
, because it required knowing both the previous and new mass properties of the collider. Same for mass property updates caused by adding or removing colliders.Now, it doesn't directly change the body's mass properties, but instead triggers an
OnColliderMassPropertiesChanged
event that theMassPropertyPlugin
(and users) can react to. This makes the collider logic only responsible for managingColliderMassProperties
, and the logic for rigid bodies is self-contained.Migration Guide
The
MassPropertyPlugin
is now needed to update mass properties automatically based on attached colliders. Most apps won't need to add it manually, as it is included in thePhysicsPlugins
plugin group by default.