* Get bevy 0.17 compiling and running (#72) * get bevy 0.17 compiling and running * try to fix CI breaking from const assertion for client/server features * fix `bin` -> `lib` for `shared` in CI * typo * fix some collider issues (#73) * Physics/controller improvements (#74) * trying to fix physics prediction * fixed prediction desync * substantial controller improvements * Finish off main bevy 0.17 migration (#75) * fix lookdir issues - airplane moving backwards - player model facing backwards - camera was technically backwards the whole time, and player models were facing the right way; camera is now facing forwards - firing without a target now respects lookdir * fix aim targeting * migrate to bevy_trenchbroom 0.10 crates release * fixed colliders not being adjusted out of worldspace * predict platforms to stop constant rollbacks while riding them * fix key/head drop visuals not working * Fix key/head drop random initial force * fixed static head drops duplicating * fix platform velocity inheritance * fix thrown projectiles not autorotating * fix inconsistent explosion animations * update avian3d to 0.4.1 * fix controller snapping to fixed angle upon switching heads * clean up commented code * fix broken physics positions * Clean comments, fix warnings (#77) * clean comments, fix warnings * fix missing import * steamworks 162 libs * fix mouselook --------- Co-authored-by: extrawurst <mail@rusticorn.com>
108 lines
2.9 KiB
Rust
108 lines
2.9 KiB
Rust
use crate::{
|
|
GameState,
|
|
camera::{CameraState, MainCamera},
|
|
global_observer,
|
|
tb_entities::{CameraTarget, CutsceneCamera, CutsceneCameraMovementEnd},
|
|
};
|
|
use bevy::prelude::*;
|
|
use bevy_trenchbroom::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Clone, Debug, Event, Serialize, Deserialize)]
|
|
pub struct StartCutscene(pub String);
|
|
|
|
#[derive(Resource, Debug, Default)]
|
|
enum CutsceneState {
|
|
#[default]
|
|
None,
|
|
Playing {
|
|
timer: Timer,
|
|
camera_start: Transform,
|
|
camera_end: Transform,
|
|
},
|
|
}
|
|
|
|
pub fn plugin(app: &mut App) {
|
|
app.init_resource::<CutsceneState>();
|
|
app.add_systems(Update, update.run_if(in_state(GameState::Playing)));
|
|
|
|
global_observer!(app, on_start_cutscene);
|
|
}
|
|
|
|
fn on_start_cutscene(
|
|
trigger: On<StartCutscene>,
|
|
mut cam_state: ResMut<CameraState>,
|
|
mut cutscene_state: ResMut<CutsceneState>,
|
|
cutscenes: Query<(&Transform, &CutsceneCamera, &Target), Without<MainCamera>>,
|
|
cutscene_movement: Query<
|
|
(&Transform, &CutsceneCameraMovementEnd, &Target),
|
|
Without<MainCamera>,
|
|
>,
|
|
cam_target: Query<(&Transform, &CameraTarget), Without<MainCamera>>,
|
|
) {
|
|
let cutscene = trigger.event().0.clone();
|
|
|
|
cam_state.cutscene = true;
|
|
|
|
// asumes `name` and `targetname` are equal
|
|
let Some((t, _, target)) = cutscenes
|
|
.iter()
|
|
.find(|(_, cutscene_camera, _)| cutscene == cutscene_camera.name)
|
|
else {
|
|
return;
|
|
};
|
|
|
|
let move_end = cutscene_movement
|
|
.iter()
|
|
.find(|(_, _, target)| cutscene == target.target.clone().unwrap_or_default())
|
|
.map(|(t, _, _)| *t)
|
|
.unwrap_or_else(|| *t);
|
|
|
|
let Some((target, _)) = cam_target.iter().find(|(_, camera_target)| {
|
|
camera_target.targetname == target.target.clone().unwrap_or_default()
|
|
}) else {
|
|
return;
|
|
};
|
|
|
|
*cutscene_state = CutsceneState::Playing {
|
|
timer: Timer::from_seconds(2.0, TimerMode::Once),
|
|
camera_start: t.looking_at(target.translation, Vec3::Y),
|
|
camera_end: move_end.looking_at(target.translation, Vec3::Y),
|
|
};
|
|
}
|
|
|
|
fn update(
|
|
mut cam_state: ResMut<CameraState>,
|
|
mut cutscene_state: ResMut<CutsceneState>,
|
|
mut cam: Query<&mut Transform, With<MainCamera>>,
|
|
time: Res<Time>,
|
|
) {
|
|
if let CutsceneState::Playing {
|
|
timer,
|
|
camera_start,
|
|
camera_end,
|
|
} = &mut *cutscene_state
|
|
{
|
|
cam_state.cutscene = true;
|
|
timer.tick(time.delta());
|
|
|
|
let t = Transform::from_translation(
|
|
camera_start
|
|
.translation
|
|
.lerp(camera_end.translation, timer.fraction()),
|
|
)
|
|
.with_rotation(
|
|
camera_start
|
|
.rotation
|
|
.lerp(camera_end.rotation, timer.fraction()),
|
|
);
|
|
|
|
let _ = cam.single_mut().map(|mut cam| *cam = t);
|
|
|
|
if timer.is_finished() {
|
|
cam_state.cutscene = false;
|
|
*cutscene_state = CutsceneState::None;
|
|
}
|
|
}
|
|
}
|