Skip to content

Add Transform-preserving hierarchy update method #5475

Closed

Description

@nicopap

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);

Activity

  1. added
    C-FeatureA new feature, making something new possible
    D-TrivialNice and easy! A great choice to get started with Bevy
    C-UsabilityA targeted quality-of-life change that makes Bevy easier to use
    A-TransformTranslations, rotations and scales
    on Jul 28, 2022
  2. removed
    D-TrivialNice and easy! A great choice to get started with Bevy
    on Jul 28, 2022
  3. changed the title [-]Add more commands to deal with hierarchy[/-] [+]Add Transform-preserving hierarchy update method[/+] on Nov 4, 2022
  4. added 2 commits that reference this issue on Jan 12, 2023
    16dda50
    689eab6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-TransformTranslations, rotations and scalesC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions