1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Expose local center of mass in physics servers

Center of mass in body's local space is more useful than the transformed
one in some cases, like drawing its position for debug.

It's especially useful to get the generated local center of mass when
in auto mode (by default).

Physics Server BODY_PARAM_CENTER_OF_MASS:
Now always returns the local center of mass, instead of setting a local
center of mass and getting a transformed one.
This causes compatibility breaking, but it makes more sense for the
parameter to be consistent between getter and setter.

Direct Body State:
There are now two properties, because both of them can be useful in
different situations.
center_of_mass: relative position in global coordinates (same as before)
center_of_mass_local: position in local coordinates
This commit is contained in:
PouleyKetchoupp
2021-10-22 11:56:00 -07:00
parent 25bea73544
commit fc8c766ef9
16 changed files with 30 additions and 6 deletions

View File

@@ -78,6 +78,7 @@ void PhysicsDirectBodyState2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_total_angular_damp"), &PhysicsDirectBodyState2D::get_total_angular_damp);
ClassDB::bind_method(D_METHOD("get_center_of_mass"), &PhysicsDirectBodyState2D::get_center_of_mass);
ClassDB::bind_method(D_METHOD("get_center_of_mass_local"), &PhysicsDirectBodyState2D::get_center_of_mass_local);
ClassDB::bind_method(D_METHOD("get_inverse_mass"), &PhysicsDirectBodyState2D::get_inverse_mass);
ClassDB::bind_method(D_METHOD("get_inverse_inertia"), &PhysicsDirectBodyState2D::get_inverse_inertia);
@@ -124,6 +125,7 @@ void PhysicsDirectBodyState2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "total_linear_damp"), "", "get_total_linear_damp");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "total_gravity"), "", "get_total_gravity");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center_of_mass"), "", "get_center_of_mass");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center_of_mass_local"), "", "get_center_of_mass_local");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "angular_velocity"), "set_angular_velocity", "get_angular_velocity");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "linear_velocity"), "set_linear_velocity", "get_linear_velocity");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sleeping"), "set_sleep_state", "is_sleeping");