bevy_rapier icon indicating copy to clipboard operation
bevy_rapier copied to clipboard

Scaling affects offsets incorrectly

Open WaDelma opened this issue 2 years ago • 1 comments

I created rigid body with two colliders and offset them to be in correct position. If I change scale of the parent entity's transformation the individual colliders scale correctly, but the offset doesn't seem to get scaled.

Screenshot from 2022-08-21 19-54-21 Screenshot from 2022-08-21 19-53-49

WaDelma avatar Aug 22 '22 17:08 WaDelma

I have the same problem. #211 and #197

pinkponk avatar Sep 22 '22 22:09 pinkponk

Yep, and I have this issue as well. I want to scale down the body with its colliders, which works for the most part, except that the child collider translations do not get scaled as well: afbeelding afbeelding

grunnt avatar Jun 09 '23 20:06 grunnt

Here's a minimal example of the problem:

use bevy::prelude::*;
use bevy_rapier2d::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
        .insert_resource(ClearColor(Color::BLACK))
        .insert_resource(RapierConfiguration {
            gravity: Vec2::ZERO,
            ..Default::default()
        })
        .add_plugin(RapierDebugRenderPlugin::default())
        .add_startup_system(setup)
        .run();
}

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

    let box_size = 50.0;

    // Body with two adjacent blocks and scale = 1.0
    commands
        .spawn((
            TransformBundle::from(Transform::from_xyz(0.0, 100.0, 0.0)),
            RigidBody::Dynamic,
        ))
        .with_children(|children| {
            children.spawn((
                TransformBundle::from(Transform::from_xyz(-box_size, 0.0, 0.0)),
                Collider::cuboid(box_size, box_size),
            ));
            children.spawn((
                TransformBundle::from(Transform::from_xyz(box_size, 0.0, 0.0)),
                Collider::cuboid(box_size, box_size),
            ));
        });

    // Body with two adjacent blocks and scale = 0.5
    // Here the colliders are scaled but their positions are not, so they are no longer adjacent as I would expect
    commands
        .spawn((
            TransformBundle::from(
                Transform::from_xyz(0.0, -100.0, 0.0).with_scale(Vec3::new(0.5, 0.5, 1.0)),
            ),
            RigidBody::Dynamic,
        ))
        .with_children(|children| {
            children.spawn((
                TransformBundle::from(Transform::from_xyz(-box_size, 0.0, 0.0)),
                Collider::cuboid(box_size, box_size),
            ));
            children.spawn((
                TransformBundle::from(Transform::from_xyz(box_size, 0.0, 0.0)),
                Collider::cuboid(box_size, box_size),
            ));
        });
}

The top boxes are unscaled and adjacent. The body of the bottom boxes is scaled but now the boxes are no longer adjacent, as I would expect: afbeelding

grunnt avatar Jun 13 '23 08:06 grunnt