Animation sync (#60)

This commit is contained in:
PROMETHIA-27
2025-07-29 07:32:54 -04:00
committed by GitHub
parent 0bd3fb0e80
commit c650924d68
16 changed files with 136 additions and 98 deletions

View File

@@ -2,7 +2,7 @@ use crate::{
GameState,
camera::{CameraArmRotation, CameraTarget},
cash::{Cash, CashCollectEvent},
character::AnimatedCharacter,
character::{AnimatedCharacter, Character},
control::controller_common::PlayerCharacterController,
global_observer,
head::ActiveHead,
@@ -22,10 +22,11 @@ use bevy::{
prelude::*,
window::{CursorGrabMode, PrimaryWindow},
};
use lightyear::prelude::{NetworkTarget, PredictionTarget, Replicate};
use lightyear::prelude::{ControlledBy, Lifetime, NetworkTarget, PredictionTarget, Replicate};
use serde::{Deserialize, Serialize};
#[derive(Component, Default, Serialize, Deserialize, PartialEq)]
#[require(Character)]
pub struct Player;
#[derive(Component, Default, Serialize, Deserialize, PartialEq)]
@@ -49,6 +50,7 @@ pub fn plugin(app: &mut App) {
pub fn spawn(
mut commands: Commands,
owner: Entity,
query: Query<&Transform, With<SpawnPoint>>,
asset_server: Res<AssetServer>,
heads_db: Res<HeadsDatabase>,
@@ -64,6 +66,10 @@ pub fn spawn(
.insert_server((
Replicate::to_clients(NetworkTarget::All),
PredictionTarget::to_clients(NetworkTarget::All),
ControlledBy {
owner,
lifetime: Lifetime::SessionBased,
},
))
.observe(on_kill);
@@ -96,7 +102,7 @@ fn player_bundle(transform: Transform, heads_db: &Res<HeadsDatabase>) -> impl Bu
Name::new("player-rig"),
PlayerBodyMesh,
CameraArmRotation,
children![AnimatedCharacter::new(0)]
children![AnimatedCharacter::new(0)],
)],
)
}