#I need my child entity to stop moving with the parent

8 messages · Page 1 of 1 (latest)

jolly harness
#

For my 2D game I'm creating a reticle that rotates around the player entity. The reticle is a child of the parent. I wanted to do things this way because it lets the player walk around while the reticle can follow the player without extra work.

My problem is I want to be able to "lock" the reticle with a keypress, at which point it should not move at all. I can't figure out how to do this.

Is there any way to stop the parents transforms from propagating to the child? I would like to keep the the rest of the parent/child relationship between the reticle and the player if possible.

If not, can I change the child so that it is no longer a child of the parent, without removing the child entity altogether?

jolly harness
#

Of course I realized how to remove parents just a few minutes after making this post.
commands.entity(child_id).remove_parents, for anyone that might try to find this.

This still isnt my ideal solution though, so yea if theres any way to stop the entity from moving even when it is the child of another entity, I'd love to know

neat condor
#

Not possible. Transform propagation is currently integral part of the hierarchy

#

If you want to remove the parent and keep the same position, you can solve this with a bit of math

#

Though bevy changed since last time I wrote the math, so I can't give you the code

neat condor
#

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.
```rust
let new_transform = transform_relative_to(entity_transform, parent_transform);
commands.entity(entity).set_parent(new_parent).insert(new_transform);
fierce plank
#

Hello! I am struggling about how to do this '''commands.entity(child_id).remove_parents''' in bevy 0.10.0 . Is there a similar function, or am I doing something wrong? I tried sifferent things but all of them are for previous versions. '''commands.entity( game.player.busy.unwrap() ).remove_parents();''' In busy, i keep an entity id of the other entity which is the child and the player is busy, or none if the player is not busy. commands.entity( game.player.busy.unwrap() ).remove_parents();
| ^^^^^^^^^^^^^^ method not found in EntityCommands<'_, '_, '_> Thank you very much