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

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

Description

@cark

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions