float MassOverride { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

The MassOverride property of the Rigidbody class allows you to specify a custom mass for the rigid body. This override is only applied when the value is greater than zero. If the value is zero or less, the default mass calculation based on the object's volume and density will be used.

Usage

To use the MassOverride property, simply set it to a positive floating-point value to override the default mass of the rigid body. This can be useful when you need to simulate objects with specific mass characteristics that differ from their physical size or density.

Example

// Example of setting the MassOverride property
Rigidbody rigidbody = new Rigidbody();
rigidbody.MassOverride = 10.0f; // Sets the mass to 10 units, overriding the default calculation

// If you want to reset to default mass calculation, set it to zero or a negative value
rigidbody.MassOverride = 0.0f; // Resets to default mass calculation based on volume and density