trail gradient
This commit is contained in:
@@ -136,7 +136,11 @@ fn on_trigger_missile(
|
|||||||
SceneRoot(asset.scenes[0].clone()),
|
SceneRoot(asset.scenes[0].clone()),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Trail::new(t.translation, LinearRgba::rgb(0.9, 0.9, 0.)),
|
Trail::new(
|
||||||
|
t.translation,
|
||||||
|
LinearRgba::rgb(1., 0.0, 0.),
|
||||||
|
LinearRgba::rgb(0.9, 0.9, 0.)
|
||||||
|
),
|
||||||
Gizmo {
|
Gizmo {
|
||||||
handle: gizmo_assets.add(GizmoAsset::default()),
|
handle: gizmo_assets.add(GizmoAsset::default()),
|
||||||
line_config: GizmoLineConfig {
|
line_config: GizmoLineConfig {
|
||||||
|
|||||||
@@ -5,14 +5,19 @@ use crate::GameState;
|
|||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct Trail {
|
pub struct Trail {
|
||||||
points: Vec<Vec3>,
|
points: Vec<Vec3>,
|
||||||
col: LinearRgba,
|
col_start: LinearRgba,
|
||||||
|
col_end: LinearRgba,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Trail {
|
impl Trail {
|
||||||
pub fn new(pos: Vec3, col: LinearRgba) -> Self {
|
pub fn new(pos: Vec3, col_start: LinearRgba, col_end: LinearRgba) -> Self {
|
||||||
let mut v = Vec::with_capacity(12);
|
let mut v = Vec::with_capacity(12);
|
||||||
v.push(pos);
|
v.push(pos);
|
||||||
Self { points: v, col }
|
Self {
|
||||||
|
points: v,
|
||||||
|
col_start,
|
||||||
|
col_end,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&mut self, pos: Vec3) {
|
pub fn add(&mut self, pos: Vec3) {
|
||||||
@@ -44,7 +49,8 @@ fn update_trail(
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
for window in trail.points.windows(2) {
|
let lerp_denom = trail.points.len() as f32;
|
||||||
|
for (i, window) in trail.points.windows(2).enumerate() {
|
||||||
let [a, b] = window else {
|
let [a, b] = window else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
@@ -55,7 +61,11 @@ fn update_trail(
|
|||||||
.reparented_to(parent_transform)
|
.reparented_to(parent_transform)
|
||||||
.translation;
|
.translation;
|
||||||
|
|
||||||
gizmo.line(a, b, trail.col);
|
gizmo.line(
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
trail.col_start.mix(&trail.col_end, i as f32 / lerp_denom),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user