-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Proper support for custom mass properties in 2D/3D physics bodies #49610
Proper support for custom mass properties in 2D/3D physics bodies #49610
Conversation
44e1201
to
975d99f
Compare
975d99f
to
113cdd4
Compare
Rebased and added the possibility to set a custom center of mass in |
113cdd4
to
3b04109
Compare
Changes: -Added support for custom inertia and center of mass in 3D -Added support for custom center of mass in 2D -Calculated center of mass from shapes in 2D (same as in 3D) -Fixed mass properties calculation with disabled shapes in 2D/3D -Removed first_integration which is not used in 2D and doesn't seem to make a lot of sense (prevents omit_force_integration to work during the first frame) -Support for custom inertia on different axes for RigidBody3D
3b04109
to
82ea2a7
Compare
Could this be cherry-picked to 3.x by setting the default center_of_mass to use Custom, Vector3(0,0,0) to avoid breaking compatibility? |
@Zoomulator Ok, it should be possible but I need to check what can be safely backported as there are changes in the way things are calculated in the physics server itself. |
@pouleyKetchoupp I worried that there might be adjacent changes in 4.0. |
Default center of mass in 2D:
Compute center of mass based on shapes by default in 2D, same as in 3D.
This change breaks compatibility because it was always using the center of the body before, although in common cases the computed center of mass is still going to be at the center.
Custom center of mass:
Can be set through the physics server using:
PhysicsServer2D.body_set_param(get_rid(), PhysicsServer2D.BODY_PARAM_CENTER_OF_MASS, center_of_mass)
Can be reset through the physics server using:
PhysicsServer2D.body_reset_mass_properties(get_rid())
3D uses a similar API.
Edit: Now can be set in
RigidBody2D
andRigidBody3D
nodes as well with properties:center_of_mass_mode: set to Auto or Custom
center_of_mass: custom center of mass (relative to the body's center)
Custom inertia:
Can be set through the physics server using:
PhysicsServer2D.body_set_param(get_rid(), PhysicsServer2D.BODY_PARAM_INERTIA, inertia)
Can be reset through the physics server using:
PhysicsServer2D.body_reset_mass_properties(get_rid())
Can be also set on rigid body nodes through the
inertia
property, with 0 meaning default calculated inertia.3D has a similar API, although it's also possible to setup a custom inertia on specific axes, and set the other ones to 0 in order to keep the default computation. That's useful to make a body rotate more or less easily on a specific axis, without affecting other axes.
Full list of changes:
-Added support for custom inertia and center of mass in 3D
-Added support for custom center of mass in 2D
-Calculated center of mass from shapes in 2D (same as in 3D)
-Updated forces and joints to use center of mass in 2D
-Fixed mass properties calculation with disabled shapes in 2D/3D
-Removed
first_integration
which is not used in 2D and doesn't seem to make a lot of sense (prevents omit_force_integration to work during the first frame)-Support for custom inertia on different axes for
RigidBody3D
-
mass
property uses a more reasonable slider range by default (max 1000), with the possibility to set higher valuesCloses #godotengine/godot-proposals#945
Fixes #12353
Supersedes #29867
Addresses issue from #49185 (review)