Skip to main content

concinnity_core/components/
body_dynamics.rs

1// src/components/body_dynamics.rs
2
3use crate::ecs::AudioClipHandle;
4
5/// Dynamic-body parameters attached to an entity with a `Collider`.
6///
7/// Runtime-only. Carries the physical values a `PropBody` declares, resolved
8/// onto the owning prop's entity at load so runtime spawns can copy them; an
9/// entity with a `Collider` but no `BodyDynamics` is a static obstacle.
10#[derive(Debug, Clone, Copy)]
11pub struct BodyDynamics {
12    /// Mass in kilograms. 0 derives mass from the collider shape.
13    pub mass: f32,
14    /// Coulomb friction coefficient.
15    pub friction: f32,
16    /// Bounciness in [0, 1].
17    pub restitution: f32,
18    /// Multiplier applied to world gravity for this body.
19    pub gravity_scale: f32,
20    /// Linear velocity damping, modelling air drag.
21    pub linear_damping: f32,
22    /// Clip played at the contact point when this body collides hard enough
23    /// to publish a contact event.
24    pub impact_clip: Option<AudioClipHandle>,
25    /// Linear gain applied to the impact clip at full impulse.
26    pub impact_volume: f32,
27}
28
29impl Default for BodyDynamics {
30    fn default() -> Self {
31        Self {
32            mass: 0.0,
33            friction: 0.5,
34            restitution: 0.0,
35            gravity_scale: 1.0,
36            linear_damping: 0.05,
37            impact_clip: None,
38            impact_volume: 1.0,
39        }
40    }
41}