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

Parent scale ignored if child doesn't have transform bundle #555

Open
andrewbaxter opened this issue Jul 4, 2024 · 2 comments
Open

Parent scale ignored if child doesn't have transform bundle #555

andrewbaxter opened this issue Jul 4, 2024 · 2 comments

Comments

@andrewbaxter
Copy link

In normal bevy afaict a child entity is affected by parent transforms regardless of whether it has a transform bundle itself or not. If it isn't present, it's as if the child had the default transforms.

Bevy Rapier seems to only respect the parent scale if the child has a transform bundle too.

Here's a small example:

use bevy::prelude::*;
use bevy_rapier3d::prelude::*;

fn main() {
    App::new()
        .insert_resource(ClearColor(Color::srgb(0xF9 as f32 / 255.0, 0xF9 as f32 / 255.0, 0xFF as f32 / 255.0)))
        .add_plugins(
            (DefaultPlugins, RapierPhysicsPlugin::<NoUserData>::default(), RapierDebugRenderPlugin::default()),
        )
        .add_systems(Startup, (setup_graphics, setup_physics))
        .run();
}

pub fn setup_graphics(mut commands: Commands) {
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(-30.0, 30.0, 100.0).looking_at(Vec3::new(0.0, 10.0, 0.0), Vec3::Y),
        ..Default::default()
    });
}

pub fn setup_physics(mut commands: Commands) {
    // Ground
    let ground_size = 200.1;
    let ground_height = 0.1;
    commands.spawn(
        (
            TransformBundle::from(Transform::from_xyz(0.0, -ground_height, 0.0)),
            Collider::cuboid(ground_size, ground_height, ground_size),
        ),
    );
    commands.spawn_empty().insert(RigidBody::Dynamic).insert(TransformBundle::from_transform(Transform {
        translation: Vec3::new(0., 10., 0.),
        scale: Vec3::new(0.5, 0.5, 0.5),
        ..Default::default()
    })).with_children(|commands| {
        commands.spawn_empty().insert(Collider::cuboid(1., 1., 1.));
    });
    commands.spawn_empty().insert(RigidBody::Dynamic).insert(TransformBundle::from_transform(Transform {
        translation: Vec3::new(5., 10., 0.),
        scale: Vec3::new(0.5, 0.5, 0.5),
        ..Default::default()
    })).with_children(|commands| {
        commands.spawn_empty().insert(TransformBundle::default()).insert(Collider::cuboid(1., 1., 1.));
    });
}
@andrewbaxter
Copy link
Author

#441 Just found this, here's another user getting tripped up.

@andrewbaxter
Copy link
Author

andrewbaxter commented Jul 4, 2024

This also looks related: #172

To clarify, I think if the parent transform were ignored entirely this wouldn't be as much of an issue, it's the fact that the parent transform is only applied sometimes, due to seemingly unrelated changes to another entity, that this is an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant