Skip to content

Commit

Permalink
Don't set z translation in 2D
Browse files Browse the repository at this point in the history
  • Loading branch information
Jondolf committed Jul 10, 2023
1 parent ac05b02 commit 56d6e86
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/plugins/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn init_rigid_bodies(
if let Some(ref mut transform) = transform {
#[cfg(feature = "2d")]
{
transform.translation = pos.extend(0.0).as_f32();
transform.translation = pos.extend(transform.translation.z).as_f32();
}
#[cfg(feature = "3d")]
{
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ fn sync_transforms(
if let Ok((parent_transform, parent_pos, parent_rot)) = parents.get(**parent) {
// Compute the global transform of the parent using its Position and Rotation
let parent_transform = parent_transform.compute_transform();
let parent_pos =
parent_pos.map_or(parent_transform.translation, |pos| pos.extend(0.0).as_f32());
let parent_pos = parent_pos.map_or(parent_transform.translation, |pos| {
pos.extend(parent_transform.translation.z).as_f32()
});
let parent_rot = parent_rot.map_or(parent_transform.rotation, |rot| {
Quaternion::from(*rot).as_f32()
});
Expand All @@ -51,7 +52,7 @@ fn sync_transforms(
// The new local transform of the child body,
// computed from the its global transform and its parents global transform
let new_transform = GlobalTransform::from(
Transform::from_translation(pos.extend(0.0).as_f32())
Transform::from_translation(pos.extend(transform.translation.z).as_f32())
.with_rotation(Quaternion::from(*rot).as_f32()),
)
.reparented_to(&GlobalTransform::from(parent_transform));
Expand All @@ -60,7 +61,7 @@ fn sync_transforms(
transform.rotation = new_transform.rotation;
}
} else {
transform.translation = pos.extend(0.0).as_f32();
transform.translation = pos.extend(transform.translation.z).as_f32();
transform.rotation = Quaternion::from(*rot).as_f32();
}
}
Expand Down

0 comments on commit 56d6e86

Please sign in to comment.