#Dynamically change component tag?

7 messages · Page 1 of 1 (latest)

little nest
#

I do not think my approach is the correct one. I have a camera controller that I want to change what transform it follows. To rephrase I want to switch between multiple transforms that my camera will follow. Here is what I do today for context:

#[derive(Component)]
pub struct FollowMarker;

commands.spawn((PbrBundle {
        mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
        material: materials.add(Color::srgb_u8(124, 144, 255)),
        transform: Transform::from_xyz(0.0, 0.5, 0.0),
        ..default()
    },
        FollowMarker,
    ));

pub fn update_follow(
    mut query: Query<&mut Transform, With<FollowMarker>>,
) {
}
#

I would also like to ask if component tag is the right name ?

solar hinge
#

I think I've seen Marker used conventionally but if you prefer Tag then use that.

That system you have currently will allow you to mutate the transform of your camera entity to, for example, make it look at a specific point in space.

little nest
#

I dont know what happen there. I copied the wrong example...
I updated the code in my original question.

Lets say I want to make another system that tells the CameraController to follow another transform. How can I achieve that?

empty pecan
#

if i understood correctly, you have a camera that follows an entity, and at times you want to change the entity that the camera is following, right?

#

change the FollowMarker to have an Entity member and add it TO THE CAMERA, then when you want to change the entity that the camera is following, just change the entity that the component is holding

#
#[derive(Component)]
struct Follower(Entity);

fn setup(mut commands: Commands) {
    let player = commands.spawn(PbrBundle {
        ..Default::default()
    }).id();
    commands.spawn(
        (
            Camera3dBundle {
                ..Default::default()
            },
            Follower(player)
         )
    );
}