-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add Transform-preserving hierarchy update method #5475
Copy link
Copy link
Closed
Labels
A-TransformTranslations, rotations and scalesTranslations, rotations and scalesC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to use
Description
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);Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-TransformTranslations, rotations and scalesTranslations, rotations and scalesC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to use