use bevy::prelude::*; use lightyear::prelude::*; use bevy::ecs::entity::MapEntities; use lightyear::input::native::plugin::InputPlugin; use serde::{Deserialize, Serialize}; use crate::block::Block; use crate::player::Player; #[derive(Default, Deserialize, Serialize, Reflect, Clone, PartialEq, Debug)] pub struct Inputs { pub movement: Vec2, pub up: bool, pub down: bool, } impl MapEntities for Inputs { fn map_entities(&mut self, _entity_mapper: &mut E) {} } pub struct ProtocolPlugin; impl Plugin for ProtocolPlugin { fn build(&self, app: &mut App) { app.add_plugins(InputPlugin::::default()); // marker components app.register_component::(); app.register_component::(); app.register_component::() .add_prediction() .add_interpolation_with(interpolate_transform); // unified update systems app.add_systems(FixedUpdate, crate::player::movement); } } fn interpolate_transform(start: Transform, other: Transform, t: f32) -> Transform { Transform { translation: start.translation.lerp(other.translation, t), rotation: start.rotation.slerp(other.rotation, t), scale: start.scale.lerp(other.scale, t), } }