#Dealing with parent/child relationships and updating transform

9 messages · Page 1 of 1 (latest)

upper narwhal
#

I guess these two problems are actually one in the same

upper narwhal
#

winces maybe something like this?

#
fn render_rotation(
    mut query: Query<(&mut Transform, &AntAngle, &AntFacing, Entity), Changed<AntFacing>>,
    mut fixed_query: Query<(&mut Transform, &Parent), With<FixedRotation>>,
) {
    for (mut transform, &angle, &facing, entity) in query.iter_mut() {
        let angle_radians = angle as u32 as f32 * std::f32::consts::PI / 180.0 * get_xflip(facing);
        transform.rotation = Quat::from_rotation_z(angle_radians);

        fixed_query.iter_mut().for_each(|(mut transform, parent)| {
            if parent.get() == entity {
                transform.rotation = Quat::from_rotation_z(-angle_radians);
            }
        });
    }
}

It could be made more performant and generic by trying to run it as a separate stage and zeroing out global transform.

#

but then there's be de-sync between the two until that stage runs which is maybe less desirable

upper narwhal
#

mmm

#

I think I might use the parent/child hierarchy but without a SpatialTransform in the parent so that I have a relationship in name only

#

move the position etc all to the child sprite

#

and then watch for that changing and search for related labels by identifying shared parent

#

I think that's the best I can do