Jondolf / avian

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

Sensor not working on AsyncSceneCollider #309

Closed dror-g closed 4 months ago

dror-g commented 9 months ago

Hi, seems like Sensor has no effect on AsyncSceneCollider.
Objects collide with it and cannot pass through it.

    commands.spawn((
      scene.clone(),
      RigidBody::Static,
      Sensor,
      AsyncSceneCollider::new(Some(ComputedCollider::TriMesh))
        .with_layers_for_name("Sensor", CollisionLayers::new([Layer::One], [Layer::Two])),
    ));

I've also tried using it as parent/child collider - With Async as parent - both colliders created, but Async still won't let objects through:

    RigidBody::Static,
    AsyncSceneCollider::new(Some(ComputedCollider::TriMesh))
      .with_layers_for_name("Sensor", CollisionLayers::new([Layer::One], [Layer::Two])),
    Sensor,
    ))
    .with_children(|children| {
    children.spawn((
        Sensor,
        Collider::ball(1.0),
        Transform::from_xyz(0., 0., 0.),
        ));
    });

With Async as child - Async not created, only parent is created:

    RigidBody::Static,
    Collider::ball(1.0),
    Sensor,
    ))
    .with_children(|children| {
    children.spawn((
        AsyncSceneCollider::new(Some(ComputedCollider::TriMesh))
          .with_layers_for_name("Sensor", CollisionLayers::new([Layer::One], [Layer::Two]))
        ));
    });

Also tried including AsyncSceneCollider in a Compound collider:

    Collider::compound(vec![
        (
        Position::from(Vec3::new(0., 0., 0.)),
        Rotation::default(),
        AsyncSceneCollider::new(Some(ComputedCollider::TriMesh)).with_layers_for_name("innerCol", CollisionLayers::new([Layer::Pan], [Layer::Sheep]))
        )
    ]),

That throws an error:

| |_____^ the trait `From<bevy_xpbd_3d::components::AsyncSceneCollider>` is not implemented for `bevy_xpbd_3d::components::Collider`

294 |     pub fn compound(
    |            -------- required by a bound in this associated function
...
298 |             impl Into<Collider>,
    |                  ^^^^^^^^^^^^^^ required by this bound in `Collider::compound`

Thank you for a great crate!!!

dror-g commented 9 months ago

I'll just add that the scene is already loaded before the AsyncSceneCollider is created, in an earlier game state, so it doesn't really have to wait for it.
(The only reason I'm using the async method is because creating the collider from GltfMesh was complicated. It worked, managed to get the Mesh and generate, but could not scale it for some reason..)

janhohenheim commented 4 months ago

@dror-g FYI https://github.com/Jondolf/bevy_xpbd/pull/375 should fix the scaling issues at least

dror-g commented 4 months ago

Amazing! These bevy-native helper functions really make bevy_xpbd a great choice for bevy physics, and I think spending time on them is well worth it.

Please feel free to close the issue, I don't know when I'll get a chance to confirm this myself..

Thank you!