Closed Aleod-m closed 1 month ago
The intended way to have multiple ray or shape casters on an entity is to simply add them as child entities.
commands.spawn((
SpatialBundle::default(),
// ...the rest of your components
))
.with_children(|child_builder| {
child_builder.spawn(RayCaster::new(Vec3::new(-2.0, 0.0), Dir3::NEG_Y));
child_builder.spawn(RayCaster::new(Vec3::new(2.0, 0.0), Dir3::NEG_Y));
});
These should automatically follow the parent entity.
Having multiple ray caster components on a single entity would make queries more annoying, and it wouldn't be very ECS-friendly. We could extend the generic tag approach proposed here to almost any component, like colliders, joints, or even Bevy's meshes and sprites, but it's just generally not a good idea to have multiple instances of a "thing" on a single entity.
If you need to tag entities, use marker components, and if you need multiple instances of something, use a separate entity for each instance. If those entities should be attached to another entity, add them as children.
As described in the title.
One implementation that is interresting as it preserve current api: