# Using density and an Overview of physics properties

**URL:** <https://forum.babylonjs.com/t/using-density-and-an-overview-of-physics-properties/51729>\
**Category:** Tutorials and tips\
**Tags:** physics, density\
**Created:** [July 2, 2024, 4:13am UTC](https://forum.babylonjs.com/t/using-density-and-an-overview-of-physics-properties/51729 "2024-07-02T04:13:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HiGreg](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@HiGreg](https://forum.babylonjs.com/u/HiGreg)\
**Post date:** [July 2, 2024, 4:13am UTC](https://forum.babylonjs.com/t/using-density-and-an-overview-of-physics-properties/51729/1 "2024-07-02T04:13:28Z")

</div>

Hierarchy: mesh.physicsBody.shape.material

BODY

- .setMassProperties() - sets user properties that override calculated values:  
– mass, inertia, centerOfMass, inertiaOrientation
- .getMassProperties() - gets resultant properties, calculated then overridden
- .setLinearDamping(linDamp)
- .setAngularDamping(angDamp)
- .setGravityFactor(gravFact)

SHAPE

- .density
- other shape properties: .filterCollideMask, .filterMembershipMask, .isTrigger

MATERIAL

- .friction
- .staticFriction
- .restitution
- .frictionCombine
- .restitutionCombine  
– PhysicsMaterialCombineMode:
  - ARITHMETIC\_MEAN, (a+b)/2
  - GEOMETRIC\_MEAN, sqrt(a_a + b_b)
  - MAXIMUM (default restitution),
  - MINIMUM (default friction),
  - MULTIPLY

Using a PhysicsAggregate appears to disable calculating mass from density, even if mass is not a part of the passed parameters. Instead, use PhysicsBody directly. Shape.density must be defined/assigned before assigning the shape to physicsBody. Alternatively, assign the shape again after modifying/setting density. The default density is 1000 (i.e. 1000 kg/m^3).

> ```
> mesh.physicsBody.shape.density = 1.18 / 1000 // g/cm^3
> mesh.physicsBody.shape = mesh.physicsBody.shape // force recalc of mass from shape and density
> 
> ```

To create a PhysicsBody directly, first get the shape, then create a PhysicsBody instead of a PhysicsAggregate:

```
const defaultPhysicsShapeType = BABYLON.PhysicsShapeType.CONVEX_HULL // or MESH

const shape = new BABYLON.PhysicsShape( {type:defaultPhysicsShapeType,parameters:{mesh:mesh}}, scene );
new BABYLON.PhysicsBody(mesh,BABYLON.PhysicsMotionType.DYNAMIC,false,scene).shape = shape

shape.density = 2 // example of changing the density
mesh.physicsBody.shape = mesh.physicsBody.shape // to recalculate mass from mesh and density

```

If you scale the mesh, you’ll have to generate a new shape (and dispose the old one). Just generate the new shape and assign it to your existing body:

> mesh.physicsBody.shape = newShape

Hopefully this will save you time by not having to figure these details out. If I got anything wrong, please let me know!

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 2, 2024, 5:17am UTC](https://forum.babylonjs.com/t/using-density-and-an-overview-of-physics-properties/51729/2 "2024-07-02T05:17:40Z")

</div>

Thank you! Bookmarked!
