dimforge / bevy_rapier

Official Rapier plugin for the Bevy game engine.
https://rapier.rs
Apache License 2.0
1.23k stars 259 forks source link

Recommended way to offset a collider? #370

Open affanshahid opened 1 year ago

affanshahid commented 1 year ago

I have a body with the KinematicCharacterController component, I want to offset the collider on this body from the centre (since the sprite isn't centred). I tried the following but the character controller doesn't work without a collider attached directly to it:

commands
        .spawn(RigidBody::KinematicPositionBased)
        .insert(KinematicCharacterController::default())
        .insert(SpriteSheetBundle {
            sprite: TextureAtlasSprite {
                index: 0,
                ..Default::default()
            },
            texture_atlas: atlas,
            transform: Transform::from_xyz(0.0, 0.0, 1.0),
            ..Default::default()
        })
        .with_children(|children| {
            children
                .spawn(Collider::cuboid(6.5, 10.5))
                .insert(TransformBundle::from_transform(Transform::from_xyz(
                    1.0, -8.0, 0.0,
                )));
        });
Aceeri commented 1 year ago

Could do this with a Compound collider with a single collider:

Collider::compound(vec![(Vec3::new(1.0, -8.0, 0.0), 0.0, Collider::cuboid(6.5, 10.5))])
Vrixyz commented 3 months ago

You can also consider doing it the other way around: offset the sprite through its hierarchy.

Aceeri commented 3 months ago

You can also consider doing it the other way around: offset the sprite through its hierarchy.

Does that work with the KinematicCharacterController now?

Vrixyz commented 3 months ago

I might have misunderstood the issue, but rather than having:

I was suggesting

I think that would work, but I'm all ears if it's not enough!

For me the real issue is probably that it doesn't work without a collider 🤔.