fix missile trails (#81)
added replicated `SpawnTrail` that acts as a marker and gets picked up by the client to create the visuals.
This commit is contained in:
@@ -5,7 +5,7 @@ use crate::{
|
||||
heads_database::HeadsDatabase,
|
||||
physics_layers::GameLayer,
|
||||
protocol::{GltfSceneRoot, PlaySound},
|
||||
utils::{global_observer, trail::Trail},
|
||||
utils::{global_observer, trail::SpawnTrail},
|
||||
};
|
||||
use avian3d::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
@@ -15,7 +15,8 @@ use std::f32::consts::PI;
|
||||
const MAX_SHOT_AGES: f32 = 15.;
|
||||
const MISSLE_SPEED: f32 = 3.;
|
||||
|
||||
#[derive(Component)]
|
||||
#[derive(Component, Reflect)]
|
||||
#[reflect(Component)]
|
||||
struct MissileProjectile {
|
||||
time: f32,
|
||||
damage: u32,
|
||||
@@ -40,7 +41,6 @@ fn on_trigger_missile(
|
||||
query_transform: Query<&Transform>,
|
||||
time: Res<Time>,
|
||||
heads_db: Res<HeadsDatabase>,
|
||||
mut gizmo_assets: ResMut<Assets<GizmoAsset>>,
|
||||
) {
|
||||
let state = trigger.event().0;
|
||||
|
||||
@@ -66,6 +66,13 @@ fn on_trigger_missile(
|
||||
time: time.elapsed_secs(),
|
||||
damage: head.damage,
|
||||
},
|
||||
SpawnTrail::new(
|
||||
12,
|
||||
LinearRgba::rgb(1., 0.0, 0.),
|
||||
LinearRgba::rgb(0.9, 0.9, 0.),
|
||||
10.,
|
||||
)
|
||||
.init_with_pos(),
|
||||
Collider::capsule_endpoints(0.4, Vec3::new(0., 0., 2.), Vec3::new(0., 0., -2.)),
|
||||
CollisionLayers::new(
|
||||
LayerMask(GameLayer::Projectile.to_bits()),
|
||||
@@ -77,29 +84,11 @@ fn on_trigger_missile(
|
||||
Visibility::default(),
|
||||
transform,
|
||||
Replicated,
|
||||
children![
|
||||
(
|
||||
Transform::from_rotation(Quat::from_rotation_x(PI / 2.).inverse()),
|
||||
GltfSceneRoot::Projectile("missile".to_string()),
|
||||
Replicated,
|
||||
),
|
||||
(
|
||||
Trail::new(
|
||||
12,
|
||||
LinearRgba::rgb(1., 0.0, 0.),
|
||||
LinearRgba::rgb(0.9, 0.9, 0.)
|
||||
)
|
||||
.with_pos(transform.translation),
|
||||
Gizmo {
|
||||
handle: gizmo_assets.add(GizmoAsset::default()),
|
||||
line_config: GizmoLineConfig {
|
||||
width: 10.,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
},
|
||||
)
|
||||
],
|
||||
children![(
|
||||
Transform::from_rotation(Quat::from_rotation_x(PI / 2.).inverse()),
|
||||
GltfSceneRoot::Projectile("missile".to_string()),
|
||||
Replicated
|
||||
)],
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user