-
-
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
Correctly set mass for a rigid body with custom inertia and center of mass #78757
Correctly set mass for a rigid body with custom inertia and center of mass #78757
Conversation
Please update the title of the PR and the message of the commit to be more descriptive of what is actually being done |
If this is the correct solution it should probably be done for 2D as well for completeness |
801a537
to
075d8b2
Compare
Yes, I've just checked and it affects 2D as well. I've added another commit for RigidBody2D. |
Please note that PRs should only contain one commit as a rule, so your commits need to be squashed (with some common message for both changes). |
Removed erroneous check, which caused _inv_mass not to be calculated when RigidBody2D or RigidBody3D used both custom center of mass and custom inertia.
813f2ea
to
3bab21f
Compare
Squashed into single commit |
@aaronfranke You might be interested in center of mass prs. |
I am making an airplane simulator. I am waiting for this fix |
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.
Not 100% my area of expertise but this looks good to me. It makes sense that this code should always run even when the user sets their own values. It also makes sense why this bug wasn't discovered earlier, most people do not set custom inertia so it's unlikely that this bug would be encountered often.
Thanks! And congrats for your first merged Godot contribution 🎉 |
See #78750 for issue description.
Removed erroneous check, which caused
_inv_mass
not to be calculated when RigidBody2D or RigidBody3D used both custom center of mass and custom inertia.The only purpose of the check for
(calculate_inertia || calculate_center_of_mass)
appears to be to prevent adding bodies to the godot_space'smass_properties_update_list
. On elements of this listGodotBody3D::update_mass_properties()
is then executed.At the first glance it appears that if
calculate_inertia == false
andcalculate_center_of_mass == false
functionGodotBody3D::update_mass_properties()
would do nothing and this check inGodotBody3D::_mass_properties_changed()
is valid.This is not entirely true.
GodotBody3D::update_mass_properties()
is also used to calculate_inv_mass
, which would be left at default value if the body was omitted from mass property update and cause incorrect physics behavior as described in #78750.By removing the check for
(calculate_inertia || calculate_center_of_mass)
it can be ensured that_inv_mass
is always calculated. At the same timeGodotBody3D::update_mass_properties()
already contains checks for the above parameters, meaning that ifcalculate_inertia == false
orcalculate_center_of_mass == false
no unnecessary calculations will be executed. Checking for these parameters twice is not needed.