rapier icon indicating copy to clipboard operation
rapier copied to clipboard

Damping doesn't work on headless simulation

Open ZoroLH opened this issue 5 months ago • 0 comments

I am simulating a boat with Rapier2d, run headless, without bevy. I set both linear damping and angular damping, neither work. I can add a force to give boat a speed, but when stop adding force, the boat keep moving and never slow down.

rapier2d = "=0.27.0"

`
pub fn new(config: &VehicleConfig) -> Self { let mut rigid_body_set = RigidBodySet::new(); let mut collider_set = ColliderSet::new();

    // Create boat as a dynamic rigid body
    let rigid_body = RigidBodyBuilder::dynamic()
        .translation(vector![0.0, 0.0])
        .rotation(0.0)
        .linear_damping(0.5) // 0.1 from config
        .angular_damping(0.9) // Disable Rapier angular damping - use manual damping only
        .additional_mass_properties(MassProperties::new(
            point![0.0, 0.0],    // Center of mass
            config.mass as Real, // Mass
            Self::calculate_boat_moment_of_inertia(config.mass, config.length, config.width), // Realistic boat hull inertia
        ))
        .build();

    let boat_handle = rigid_body_set.insert(rigid_body);

    // Create boat collider (rectangular hull)
    let collider =
        ColliderBuilder::cuboid((config.length / 2.0) as Real, (config.width / 2.0) as Real)
            .build(); // Remove mass from collider - rigid body has mass

    collider_set.insert_with_parent(collider, boat_handle, &mut rigid_body_set);

    // Setup physics world with no gravity (2D water simulation)
    let gravity = vector![0.0, 0.0];
    let integration_parameters = IntegrationParameters::default();
    let physics_pipeline = PhysicsPipeline::new();
    let island_manager = IslandManager::new();
    let broad_phase = DefaultBroadPhase::new();
    let narrow_phase = NarrowPhase::new();
    let impulse_joint_set = ImpulseJointSet::new();
    let multibody_joint_set = MultibodyJointSet::new();
    let ccd_solver = CCDSolver::new();

    Self {
        config: config.clone(),
        rigid_body_set,
        collider_set,
        gravity,
        integration_parameters,
        physics_pipeline,
        island_manager,
        broad_phase,
        narrow_phase,
        impulse_joint_set,
        multibody_joint_set,
        ccd_solver,
        boat_handle,
        current_thrust_force: vector![0.0, 0.0],
        current_torque: 0.0,
    }
}`

ZoroLH avatar Aug 05 '25 18:08 ZoroLH