bevy_rapier icon indicating copy to clipboard operation
bevy_rapier copied to clipboard

Collider::set_contact_force_event_threshold is missing

Open CleanCut opened this issue 3 years ago • 2 comments

The documentation says:

...the engine will compute the sum of the magnitude of all the contacts between the two colliders and only trigger a contact force event if that magnitude is larger than the threshold set with ColliderBuilder::contact_force_event_threshold or Collider::set_contact_force_event_threshold (defaults to 0) for any of the two colliders with the...

1. Collider::set_contact_force_event_threshold does not exist in bevy_rapier2d.

It's just not there.

2. ColliderBuilder::contact_force_event_threshold is not easily usable.

For example, if you try this code

let collider = ColliderBuilder::ball(radius)
    .contact_force_event_threshold(0.0)
    .build();

commands
    // spawn a sprite and insert lots of other components
    .insert(collider);

you get the error:

   Compiling cirena v0.1.0 (/Users/nathan/rust/cirena)
error[E0277]: the trait bound `bevy_rapier2d::rapier2d::geometry::Collider: bevy::prelude::Component` is not satisfied
   --> src/main.rs:140:17
    |
140 |         .insert(collider);
    |          ------ ^^^^^^^^ the trait `bevy::prelude::Component` is not implemented for `bevy_rapier2d::rapier2d::geometry::Collider`
    |          |
    |          required by a bound introduced by this call
    |
    = help: the following other types implement trait `bevy::prelude::Component`:
              ActionStateDriver<A>
              AdditionalMassProperties
              AlphaMode
              AnimationPlayer
              Button
              CalculatedClip
              CalculatedSize
              Camera
            and 114 others
note: required by a bound in `EntityCommands::<'w, 's, 'a>::insert`
   --> /Users/nathan/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_ecs-0.8.1/src/system/commands/mod.rs:533:46
    |
533 |     pub fn insert(&mut self, component: impl Component) -> &mut Self {
    |                                              ^^^^^^^^^ required by this bound in `EntityCommands::<'w, 's, 'a>::insert`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `cirena` due to previous error

~I did manage to finally get it to compile by extracting the collider builder's shape and converting that to a collider:~ ...which doesn't work, see comment below.

// this compiles
let shape = ColliderBuilder::ball(radius)
    .contact_force_event_threshold(0.0)
    .shape;

commands
    // spawn a sprite and insert lots of other components
    .insert(Collider::from(shape));

CleanCut avatar Nov 05 '22 17:11 CleanCut

Thank you for pointing out this error! I’ll update the documentation.

The solution you reached won’t be working (the shape doesn’t store the contact force threshold). The correct solution is to insert the ContactForceEventThreshold component alongside the Collider component.

sebcrozet avatar Nov 05 '22 18:11 sebcrozet

❤️ Good to know, thanks!

CleanCut avatar Nov 05 '22 20:11 CleanCut