dimforge / rapier

2D and 3D physics engines focused on performance.
https://rapier.rs
Apache License 2.0
3.97k stars 248 forks source link

changing RidigBody component at runtime make it stops #513

Open Nathan-M-code opened 1 year ago

Nathan-M-code commented 1 year ago

I am playing with a ball like this

commands
        .spawn(ShapeBundle {
            path: GeometryBuilder::build_as(&shape),
            transform: Transform::from_translation(Vec3::new(0., 200., 10.)),
            ..default()
        })
        .insert(Fill::color(Color::CYAN))
        .insert(RigidBody::KinematicPositionBased)
        .insert(Collider::ball(radius))
        .insert(Restitution::coefficient(0.7))
        .insert(Velocity::zero())
        .insert(ColliderMassProperties::Density(1.))
        .insert(Sleeping{
            linear_threshold: -1.,
            angular_threshold: -1.,
            sleeping: false,
        })
        .insert(ExternalImpulse {
            ..default()
        })
        .insert(Damping { linear_damping: 0.3, angular_damping: 1.0 })
        .insert(Player{
            being_dragged: false,
            max_distance_this_launch: 0.,
            max_height_this_launch: 0.,
        });

Then when user mouse release

   else if mouse_button.just_released(MouseButton::Left){
        //(&mut Player, &mut RigidBody, &Transform, &Collider, &mut ExternalImpulse)
        if player_tuple.0.being_dragged {
            player_tuple.0.being_dragged = false;
            player_tuple.0.max_distance_this_launch = 0.;
            player_tuple.0.max_height_this_launch = 0.;
            player_tuple.4.impulse = Vec2::new(100.0, 200.0);
            *player_tuple.1 = RigidBody::Dynamic;
            next_state.set(AppState::Forwarding);
        }
    }

Then there are two cases:

Did I miss something ?

Nathan-M-code commented 1 year ago

Indeed, there is no probleme now if I add player_tuple.5.sleeping = false;

Then why my threshold are not read ?

Vrixyz commented 4 months ago

This seems similar to https://github.com/dimforge/rapier/issues/616 ; do you still encounter issues with rapier >= 0.19 ?