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

Recommended way to offset a collider? #370

Open
affanshahid opened this issue May 6, 2023 · 4 comments
Open

Recommended way to offset a collider? #370

affanshahid opened this issue May 6, 2023 · 4 comments
Labels
A-Dynamics C-Bug Something isn't working P-Medium S-not-started Work has not started

Comments

@affanshahid
Copy link

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
Copy link
Contributor

Aceeri commented Jul 24, 2023

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
Copy link
Contributor

Vrixyz commented May 20, 2024

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

@Aceeri
Copy link
Contributor

Aceeri commented May 21, 2024

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

Does that work with the KinematicCharacterController now?

@Vrixyz
Copy link
Contributor

Vrixyz commented May 23, 2024

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

  • parent with sprite + rigidbody
    • child with collider

I was suggesting

  • parent with rigidbody + collider
    • child with sprite, which you can specify any offset you want.

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 🤔.

@Vrixyz Vrixyz added C-Bug Something isn't working P-Medium S-not-started Work has not started A-Dynamics labels May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Dynamics C-Bug Something isn't working P-Medium S-not-started Work has not started
Projects
None yet
Development

No branches or pull requests

3 participants