Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

zero-length normals during RigidBody::Sensor collision detection #240

Open
cark opened this issue Apr 15, 2022 · 2 comments
Open

zero-length normals during RigidBody::Sensor collision detection #240

cark opened this issue Apr 15, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@cark
Copy link

cark commented Apr 15, 2022

The normals vector is of 0 length when detecting a collision between Sensors.
This works fine for RigidBody::Dynamic, but for my particular use case I cannot interact with the other simulated bodies.

Here is a repository with an (hopefully minimal enough) example: https://github.com/cark/HeronMissingNormals

Code reproduced here:

use bevy::prelude::*;
use heron::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(PhysicsPlugin::default())
        .add_startup_system(init)
        .add_system(movement)
        .add_system(collision_detection)
        .run();
}

#[derive(Component)]
struct Speed(Vec2);

fn spawn_entity(commands: &mut Commands, position: Vec2, speed: Vec2) {
    commands
        .spawn()
        .insert(Speed(speed))
        .insert(Transform::from_translation(position.extend(0.0)))
        .insert(GlobalTransform::default())
        .insert(RigidBody::Sensor)
        .insert(CollisionShape::Sphere { radius: 10.0 });
}

fn init(mut commands: Commands) {
    commands.spawn_bundle(OrthographicCameraBundle::new_2d());
    spawn_entity(&mut commands, Vec2::new(-100.0, 0.0), Vec2::new(1.0, 0.0));
    spawn_entity(&mut commands, Vec2::new(100.0, 0.0), Vec2::new(-1.0, 0.0));
}

fn movement(mut query: Query<(&Speed, &mut Transform)>) {
    for (speed, mut transform) in query.iter_mut() {
        transform.translation.x += speed.0.x;
        transform.translation.y += speed.0.y;
    }
}

fn collision_detection(mut events: EventReader<CollisionEvent>) {
    for event in events.iter() {
        if let CollisionEvent::Started(d1, d2) = event {
            info!(
                "normal count 1: {}, normal count 2: {}",
                d1.normals().len(),
                d2.normals().len()
            );
        }
    }
}

Notice the collision_detection function, I log the length of the normal vectors there.

What i hoped to see in the console:

2022-04-14T20:34:52.409381Z  INFO heron_test: normal count 1: 1, normal count 2: 1

What i actually see:

2022-04-14T20:34:52.409381Z  INFO heron_test: normal count 1: 0, normal count 2: 0

I guess I could extract those normals by querying the global transforms of the entities. But I think this might be a bug, so here I am, reporting it.

@jcornaz
Copy link
Owner

jcornaz commented Apr 15, 2022

Thanks for the report.

That's because heron on only check the contact graph. It should also check the intersection graph.

@jcornaz jcornaz added bug Something isn't working up-for-grabs Good for newcomers labels Apr 15, 2022
@jcornaz jcornaz added enhancement New feature or improvement and removed bug Something isn't working labels May 9, 2022
@jcornaz jcornaz changed the title Missing normals during RigidBody::Sensor collision detection Add normals during RigidBody::Sensor collision detection May 9, 2022
@jcornaz jcornaz changed the title Add normals during RigidBody::Sensor collision detection zero-length normals during RigidBody::Sensor collision detection May 9, 2022
@jcornaz jcornaz added bug Something isn't working and removed enhancement New feature or improvement labels May 9, 2022
@Shreyan11
Copy link

Can I be assigned to this,if the bug hasn't been fixed already?

@jcornaz jcornaz removed the up-for-grabs Good for newcomers label Jun 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants