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

Collider::compound from an ellipse doesn't work correctly #369

Open
JonasAAA opened this issue Jun 12, 2024 · 0 comments
Open

Collider::compound from an ellipse doesn't work correctly #369

JonasAAA opened this issue Jun 12, 2024 · 0 comments
Labels
A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality C-Bug Something isn't working

Comments

@JonasAAA
Copy link
Contributor

Versions

bevy 0.13.2
bevy_xpbd_2d 0.4.2

Description

Collider::compound from an ellipse collider doesn't register (at least some) collisions.

Example

Below code spawns a compound collider consisting of a single ellipse and a square. The two shapes are overlapping at spawn, so that should be printed, and shapes should be moved to be disjoint. Neither of these happen.

If I use Circle::new(100.0) instead of the ellipse, everything works as expected - I get a message about entities overlapping at spawn, and the shapes are moved to no longer overlap.

use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
use bevy_xpbd_2d::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(PhysicsPlugins::default())
        .insert_resource(Gravity(Vec2::ZERO))
        .add_systems(Startup, (setup_camera, spawn_objects))
        .run();
}

fn setup_camera(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
}

fn spawn_objects(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<ColorMaterial>>,
) {
    let shape = Ellipse::new(100.0, 200.0);

    commands.spawn((
        MaterialMesh2dBundle {
            mesh: meshes.add(shape).into(),
            material: materials.add(Color::BLUE),
            transform: Transform::from_translation(Vec3::new(-50.0, 0.0, 0.0)),
            ..default()
        },
        RigidBody::Dynamic,
        Collider::compound(vec![(Vec2::ZERO, 0.0, shape)]),
    ));

    let shape = Rectangle::new(100.0, 100.0);
    commands.spawn((
        MaterialMesh2dBundle {
            mesh: meshes.add(shape).into(),
            material: materials.add(Color::YELLOW),
            transform: Transform::from_translation(Vec3::new(50.0, 0.0, 0.0)),
            ..default()
        },
        RigidBody::Dynamic,
        shape.collider(),
    ));
}
@JonasAAA JonasAAA changed the title Collider::compound from an ellipse doesn't work correctly Collider::compound from an ellipse doesn't work correctly Jun 12, 2024
@Jondolf Jondolf added C-Bug Something isn't working A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality labels Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality C-Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants