Health Bar plugin for Bevy 3D. Despite its name, this plugin is universally applicable. It can be used to render a bar for any value that can be represented as percentage. Can be freely sized, supports horizontal or vertical orientation, custom fore- and background colors, and an optional border with configurable thickness and color. Works with split-screens or layered cameras out of the box.
| Bevy Version | Crate Version |
|--------------|--------------:|
| 0.11
| >= 1.2.0
|
| 0.10
| 1.1.0
|
| 0.9
| 1.0.0
|
Implement the Percentage
trait for the component you want to track and pass the type of your component
to the plugin on instantiation:
```rust use bevyhealthbar3d::prelude::{HealthBarPlugin, Percentage};
struct Health { max: f32, current: f32, }
impl Percentage for Health { fn value(&self) -> f32 { self.current / self.max } }
fn main() {
App::new()
.addplugin(HealthBarPlugin::
Spawn a mesh, the component to be tracked, and a BarBundle
to configure the look & feel of your bar.
rust
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Icosphere { radius, ..default() })),
// ...
},
Health {
max: 10.,
current: 2.,
},
BarBundle::<Health> {
width: BarWidth::new(mesh_width),
offset: BarOffset::new(mesh_height),
orientation: BarOrientation::Vertical, // defaults is horizontal
..default()
},
));
}
Note the generic parameter of BarBundle
. It is used to associate the configuration with the component it is tracking
and necessary to support multiple bars per entity.
That's it! Updates to the values of your component will be automatically propagated through to the bar.
Further examples can be found here