Fix center of mass when importing GLTF physics bodies

This commit is contained in:
Aaron Franke 2023-05-26 16:15:39 -05:00
parent 28cca66d2c
commit a98be434b7
No known key found for this signature in database
GPG Key ID: 40A1750B977E56BF
1 changed files with 5 additions and 0 deletions

View File

@ -112,6 +112,9 @@ Ref<GLTFPhysicsBody> GLTFPhysicsBody::from_node(const CollisionObject3D *p_body_
physics_body->linear_velocity = body->get_linear_velocity();
physics_body->angular_velocity = body->get_angular_velocity();
physics_body->inertia = body->get_inertia();
if (body->get_center_of_mass() != Vector3()) {
WARN_PRINT("GLTFPhysicsBody: This rigid body has a center of mass offset from the origin, which will be ignored when exporting to GLTF.");
}
if (cast_to<VehicleBody3D>(p_body_node)) {
physics_body->body_type = "vehicle";
} else {
@ -140,6 +143,7 @@ CollisionObject3D *GLTFPhysicsBody::to_node() const {
body->set_linear_velocity(linear_velocity);
body->set_angular_velocity(angular_velocity);
body->set_inertia(inertia);
body->set_center_of_mass_mode(RigidBody3D::CENTER_OF_MASS_MODE_CUSTOM);
return body;
}
if (body_type == "rigid") {
@ -148,6 +152,7 @@ CollisionObject3D *GLTFPhysicsBody::to_node() const {
body->set_linear_velocity(linear_velocity);
body->set_angular_velocity(angular_velocity);
body->set_inertia(inertia);
body->set_center_of_mass_mode(RigidBody3D::CENTER_OF_MASS_MODE_CUSTOM);
return body;
}
if (body_type == "static") {