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

ColliderBundle #283

Open
L1ghtingBolt opened this issue Jun 24, 2022 · 8 comments
Open

ColliderBundle #283

L1ghtingBolt opened this issue Jun 24, 2022 · 8 comments
Labels
enhancement New feature or improvement

Comments

@L1ghtingBolt
Copy link

I'm making a tilemap and that would be really useful, where is it, or something similar?

@jcornaz
Copy link
Owner

jcornaz commented Jun 24, 2022

There is none... Yet. Currently you pick the components you need, and only that.

We could potentially add bundle types. Though, I am not yet sure what to provide exactly.

Basically, only two components are required: RigidBody and CollisionShape, but the CollisionShape may be in a child entity.

@L1ghtingBolt
Copy link
Author

L1ghtingBolt commented Jun 24, 2022

There is none... Yet. Currently you pick the components you need, and only that.

We could potentially add bundle types. Though, I am not yet sure what to provide exactly.

Basically, only two components are required: RigidBody and CollisionShape, but the CollisionShape may be in a child entity.

Hey. I'm using bevy_ecs_ldtk which recommends using heron. I saw that older versions of rapier included ColliderBundle, which was a bundle of colliders that you could use to make a more detailed collider. I wanted to use that in my tiled map. bevy_ecs_ldtk makes reference to ColliderBundle on the platformer example. Would it be possible to add a collider bundle or anything similar to make a tilemap?

@L1ghtingBolt
Copy link
Author

L1ghtingBolt commented Jun 24, 2022

/// Spawns heron collisions for the walls of a level
///
/// You could just insert a ColliderBundle in to the WallBundle,
/// but this spawns a different collider for EVERY wall tile.
/// This approach leads to bad performance.
///
/// Instead, by flagging the wall tiles and spawning the collisions later,
/// we can minimize the amount of colliding entities.
///
/// The algorithm used here is a nice compromise between simplicity, speed,
/// and a small number of rectangle colliders.
/// In basic terms, it will:
/// 1. consider where the walls are
/// 2. combine wall tiles into flat "plates" in each individual row
/// 3. combine the plates into rectangles across multiple rows wherever possible
/// 4. spawn colliders for each rectangle"

Comment in the bevy_ecs_ldtk example

@jcornaz
Copy link
Owner

jcornaz commented Jun 24, 2022

As I just said above, yes we could potentially add a "bundle" type.

But I am still not so sure about which components it should contain. Should it be RigidBody and a CollisionShape? Should it include transforms?

I gess these lines from bevy_ecs_ldtk
could change from this:

commands
    .spawn()
    .insert(CollisionShape::Cuboid {
        half_extends: Vec3::new(
            (wall_rect.right as f32 - wall_rect.left as f32 + 1.)
                * grid_size as f32
                / 2.,
            (wall_rect.top as f32 - wall_rect.bottom as f32 + 1.)
                * grid_size as f32
                / 2.,
            0.,
        ),
        border_radius: None,
    })
    .insert(RigidBody::Static)

to that:

commands
    .spawn_bundle(ColliderBundle {
       body: RigidBody::Static,
       collider: CollisionShape::Cuboid {
        half_extends: Vec3::new(
            (wall_rect.right as f32 - wall_rect.left as f32 + 1.)
                * grid_size as f32
                / 2.,
            (wall_rect.top as f32 - wall_rect.bottom as f32 + 1.)
                * grid_size as f32
                / 2.,
            0.,
        ),
        border_radius: None,
      }
    }))

It doesn't change much...

And in practice, such a bundle may not be used so often, given that more complex usage would often need to spawn the collision shape in a child entity.

@jcornaz jcornaz added the enhancement New feature or improvement label Jun 24, 2022
@L1ghtingBolt
Copy link
Author

L1ghtingBolt commented Jun 24, 2022 via email

@jcornaz
Copy link
Owner

jcornaz commented Jun 24, 2022

As I said, the onli components for that bundle would be various colliders,
no rigidbody, just various colliders

That doesn't make sense to me.

I assume that by "collider" you mean CollisionShape?

You cannot insert multiple CollisionShape into a single entity. And why does it have to be a bundle if you only want to insert a single component?

@jcornaz jcornaz changed the title Where's the ColliderBundle? ColliderBundle Jun 24, 2022
@L1ghtingBolt
Copy link
Author

L1ghtingBolt commented Jun 24, 2022 via email

@jcornaz
Copy link
Owner

jcornaz commented Jun 24, 2022

Well then how to add collision to a tilemap

Insert a RigidBody (probably the Static variant) and a CollisionShape component to each tile entity that should have collision. Depending on your use case, you may also add other components such as CollisionLayers.

Maybe read the example of bevy_ecs_ldtk that you mentioned.

I think the documentation is pretty clear. If you think it isn't, please suggest a concrete improvement.

When it comes to adding a bundle type, if you want to continue the discussion, please be more precise about what components the bundle should contain in your opinion. Maybe share here your user-code version of that bundle. And explain why that would be an improvement over the current situation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or improvement
Projects
None yet
Development

No branches or pull requests

2 participants