trails and better missile origin

This commit is contained in:
2025-04-30 00:02:45 +02:00
parent f6eb652fd2
commit 4b8cc8bb71
4 changed files with 68 additions and 30 deletions

View File

@@ -10,16 +10,20 @@ pub struct Trail {
}
impl Trail {
pub fn new(pos: Vec3, col_start: LinearRgba, col_end: LinearRgba) -> Self {
let mut v = Vec::with_capacity(12);
v.push(pos);
pub fn new(points: usize, col_start: LinearRgba, col_end: LinearRgba) -> Self {
Self {
points: v,
points: Vec::with_capacity(points),
col_start,
col_end,
}
}
pub fn with_pos(self, pos: Vec3) -> Self {
let mut trail = self;
trail.add(pos);
trail
}
pub fn add(&mut self, pos: Vec3) {
if self.points.len() >= self.points.capacity() {
self.points.pop();
@@ -36,19 +40,21 @@ pub fn plugin(app: &mut App) {
}
fn update_trail(
mut query: Query<(&mut Trail, &Gizmo, &GlobalTransform, &ChildOf)>,
mut query: Query<(Entity, &mut Trail, &Gizmo, &GlobalTransform)>,
global_transform: Query<&GlobalTransform>,
mut gizmo_assets: ResMut<Assets<GizmoAsset>>,
) -> Result<(), BevyError> {
for (mut trail, gizmo, pos, parent) in query.iter_mut() {
) -> Result {
for (e, mut trail, gizmo, pos) in query.iter_mut() {
trail.add(pos.translation());
let parent_transform = global_transform.get(parent.parent())?;
let parent_transform = global_transform.get(e)?;
let Some(gizmo) = gizmo_assets.get_mut(gizmo.handle.id()) else {
continue;
};
gizmo.clear();
let lerp_denom = trail.points.len() as f32;
for (i, window) in trail.points.windows(2).enumerate() {
let [a, b] = window else {