Jondolf / avian

ECS-driven 2D and 3D physics engine for the Bevy game engine.
https://crates.io/crates/avian3d
Apache License 2.0
1.49k stars 119 forks source link

Entity are overlapping at spawn, which can result in explosive behavior. #249

Open Cupnfish opened 11 months ago

Cupnfish commented 11 months ago

https://github.com/Jondolf/bevy_xpbd/assets/40173605/327633fd-fa88-441f-9281-9ca4370a883c

When this situation occurs, the movement of the sphere feels a bit exaggerated. Is there an efficient way to limit this? I'm using the following approach to limit it:

fn limit_velocity(mut velocitys: Query<&mut LinearVelocity, Changed<LinearVelocity>>) {
    const MAX_LINVEL_Y: f32 = 150.;
    for mut velocity in velocitys.iter_mut() {
        velocity.0 = velocity.0.min(Vec2::splat(MAX_LINVEL_Y));
        // if velocity.y > MAX_LINVEL_Y {
        //     velocity.y = MAX_LINVEL_Y;
        // }
    }
}

The commented part is what I previously used when using Bevy Rapier, and I'm not sure if something is missing when I migrated it. The previous settings don't seem to work anymore.

benjamin-cates commented 11 months ago

Hello! I am developing a 3d version of this and having the same problem. I think it is related to the size of objects when they are spawning and it possibly overlaps. How are you spawning your combined circles?

Cupnfish commented 11 months ago

@benjamin-cates I have already solved this problem. Although it is indeed related to the size during generation, sometimes this kind of overlap is unavoidable. After adjusting the SubstepCount to an appropriate value, the game runs as expected. You can also give it a try (usually by reducing it).

.insert_resource(SubstepCount(3))