bevy_rapier
bevy_rapier copied to clipboard
Scaling affects offsets incorrectly
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.
I have the same problem. #211 and #197
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:
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: