use crate::{ GameState, tb_entities::{Platform, PlatformTarget}, }; use bevy::{math::ops::sin, prelude::*}; use bevy_trenchbroom::prelude::*; #[derive(Component, Reflect, Default, Debug)] #[reflect(Component)] struct ActivePlatform { pub start: Vec3, pub target: Vec3, } pub fn plugin(app: &mut App) { app.register_type::(); app.add_systems(OnEnter(GameState::Playing), init); app.add_systems( FixedUpdate, move_active.run_if(in_state(GameState::Playing)), ); } fn init( mut commands: Commands, uninit_platforms: Query< (Entity, &Target, &Transform), (Without, With), >, targets: Query<(&PlatformTarget, &Transform)>, ) { for (e, target, transform) in uninit_platforms.iter() { let Some(target) = targets .iter() .find(|(t, _)| t.targetname == target.target.clone().unwrap_or_default()) .map(|(_, t)| t.translation) else { continue; }; let platform = ActivePlatform { start: transform.translation, target, }; commands.entity(e).insert(platform); } } fn move_active(time: Res