Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changing RidigBody component at runtime make it stops #513

Open
Nathan-M-code opened this issue Aug 19, 2023 · 1 comment
Open

changing RidigBody component at runtime make it stops #513

Nathan-M-code opened this issue Aug 19, 2023 · 1 comment

Comments

@Nathan-M-code
Copy link

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:

  • I release the ball near another collider : everything is as expected
  • I release the ball far from another collider : the ball get stuck in the air with RigidBody::Dynamic and non null Velocity

Did I miss something ?

@Nathan-M-code
Copy link
Author

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

Then why my threshold are not read ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant