What problem does this solve or what need does it fill?
It is currently cumbersome and error-prone to update an entity's parent while keeping its GlobalTransform static.
What solution would you like?
I'd like a method on EntityCommands that allows updating both the parent and the transform of an entity so that they keep their GlobalTransform.
What alternative(s) have you considered?
It is possible to reparent keeping the same transform with the following code:
fn transform_relative_to(point: &GlobalTransform, reference: &GlobalTransform) -> Transform {
let relative_affine = reference.affine().inverse() * point.affine();
let (scale, rotation, translation) = relative_affine.to_scale_rotation_translation();
Transform { translation, rotation, scale }
}
Then, the following to set both the parent and the transform in order to preserve the same GlobalTransform through the hierarchy change.
let new_transform = transform_relative_to(entity_transform, parent_transform);
commands.entity(entity).set_parent(new_parent).insert(new_transform);
What problem does this solve or what need does it fill?
It is currently cumbersome and error-prone to update an entity's parent while keeping its
GlobalTransformstatic.What solution would you like?
I'd like a method on
EntityCommandsthat allows updating both the parent and the transform of an entity so that they keep theirGlobalTransform.What alternative(s) have you considered?
It is possible to reparent keeping the same transform with the following code:
Then, the following to set both the parent and the transform in order to preserve the same
GlobalTransformthrough the hierarchy change.