#Very strange: Avian and set_impulse for single or not contacted colliders

6 messages · Page 1 of 1 (latest)

uncut mortar
#

Tested on avian3d = "0.1" and bevy="0.14.0"
There are only 2 systems because the rest of the code does not fit into the quota.
So...
If there is only one cube, the impulse is not work, in case 2 or more but without gravity - too.
(without gravity cubes don't touch )
This makes me think the cubes must touch each other to impulse work 🙂
Can anyone explain this mystery?
And I should note that with bevy_xpbd_3d ="0.5" everything works as it should.


fn setup(
    mut commands: Commands,
    mut materials: ResMut<Assets<StandardMaterial>>,
    mut meshes: ResMut<Assets<Mesh>>,
) {
    let cube_mesh = meshes.add(Cuboid::default());

    let cube_size = 2.0;
    for i in 1..=2 {  // if single - dont work 
        commands.spawn((
            PbrBundle {
                mesh: cube_mesh.clone(),
                material: materials.add(Color::srgb(0.2, 0.7, 0.9)),
                transform: Transform::from_translation(vec3(0., 5. + 3. * i as f32 , 0.))
                    .with_scale(Vec3::splat(cube_size as f32)),
                ..default()
            },
            RigidBody::Dynamic,
            Collider::cuboid(1.0, 1.0, 1.0),
            ExternalImpulse::new(Vec3::ZERO).with_persistence(false),
            GravityScale(0.)   // if present - dont work
        ));
    }
}

fn movement(
    keyboard_input: Res<ButtonInput<KeyCode>>,
    mut query: Query<&mut ExternalImpulse>,
) {
    for mut external_impulse in query.iter_mut() {
        if keyboard_input.just_pressed(KeyCode::Space) {
            external_impulse.set_impulse(Vec3::X * 50.);
        }
    }
}
misty gyro
# uncut mortar Tested on avian3d = "0.1" and bevy="0.14.0" There are only 2 systems because th...

Hi! Could you try adding the SleepingDisabled component for the cubes? Bodies are marked as sleeping and deactivated when they have a low enough speed for roughly 0.5 seconds (by default) to save computational resources. Applying an impulse should wake the body up, but I'm thinking that it could be an issue where there is a one-frame delay, and the impulse is applied before the body is woken up, making it seem like the impulse has no effect.

#

If this is the issue, I think it should be pretty easy to fix

#

(also the reason xpbd 0.5 wouldn't have had this issue is that sleeping was just completely broken there lol)

uncut mortar
#

Yes ! Adding this component fixed this issue !

misty gyro
#

Cool, thanks for confirming my suspicion 😄 I'll try to get it fixed, I plan on releasing a 0.1.1 patch soon-ish