#bevy-engine #physics-simulation #gamedev-physics #gamedev #avian3d

avian_smart_damping_plugin

A plugin for Avian and Bevy engines that implements a velocity damping system based on the properties of bodies and their projections

2 releases

Uses new Rust 2024

new 0.0.2 Mar 23, 2025
0.0.1 Mar 23, 2025

#506 in Game dev

MIT license

36KB
297 lines

This is a plugin for Avian and Bevy engines that implements a velocity damping system based on the spatial position, mass and linear and angular velocities of rigid bodies, using raycasting to derive the projection area and a system of external linear and angular impulses to integrate the effect.

At the moment the plugin is not stable and is in the proof of concept stage and will most likely be abandoned, as I plan to create a more performant implementation with more features, such as air flows and aerodynamic body stabilization.

To use the plugin, you just need to register SmartDampingPlugin after the Avian plugins and add SmartDamping component to the bodies that will participate in the simulation:

fn main() {
    App::new()
        .add_plugins((
            PhysicsPlugins::default(),
            SmartDampingPlugin,
        ))
        .add_systems(Startup, setup)
        .run();
}
fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    commands.spawn((
        SmartDamping::default(),
        RigidBody::Dynamic,
        Transform::from_xyz(0.0, 2.0, 0.0),
        Collider::cuboid(1.0, 1.0, 0.1),
        Mass(1.0),
        AngularVelocity(Vec3::new(0.0, 0.0, 2.0)),
        Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 0.1))),
        MeshMaterial3d(materials.add(Color::WHITE)),
    ));
}

Video demonstrating the behavior of bodies with smart damping: Not yet

Dependencies

~25–37MB
~599K SLoC