jrouwe/JoltPhysics

How to set mass?

Closed this issue · 1 comments

Hello,

I've been looking around and can't seem to find the API for setting a body's mass, and I noticed the body I created is falling very slowly with a gravity of (0, -9.81, 0).

Is there a way I can either set the mass or make it fall faster?

Thank you!

Hi! From my understanding, you have to specify JPH::MassProperties in body settings during body creation, like:

JPH::MassProperties msp;
msp.ScaleToMass(10.0f); //actual mass in kg

bodySettings.mMassPropertiesOverride = msp;
bodySettings.mOverrideMassProperties = JPH::EOverrideMassProperties::CalculateInertia;

JPH::MassProperties have several methods for setting the mass and the inertia: https://jrouwe.github.io/JoltPhysics/class_mass_properties.html

Respectfully, adjust the EOverrideMassProperties flag if you need to calculate the inertia or not

EDIT: you can also change the gravity of the physics system itself, which I am currently experimenting with to achieve more dynamic and fast-paced world, although I don't know yet if it affects the simulation in any negative way: https://jrouwe.github.io/JoltPhysics/class_physics_system.html#ad09c12009bbcb0d0e6dbfd9582593be4