Fixes to head animations

Former-commit-id: b595d4cdb459acbdd3a9a971aff8f0fbfd45981a
This commit is contained in:
Joshua Barretto 2019-05-09 20:18:13 +01:00
parent faf53ad5c9
commit 89f9589cf0
4 changed files with 31 additions and 3 deletions

25
common/src/sys/anim.rs Normal file
View File

@ -0,0 +1,25 @@
// Library
use specs::{Join, Read, ReadStorage, System, WriteStorage};
use vek::*;
// Crate
use crate::{
comp::{phys::Pos, AnimationHistory, Control},
state::DeltaTime,
};
// Basic ECS AI agent system
pub struct Sys;
impl<'a> System<'a> for Sys {
type SystemData = (
Read<'a, DeltaTime>,
WriteStorage<'a, AnimationHistory>,
);
fn run(&mut self, (dt, mut anim_history): Self::SystemData) {
for (mut anim_history) in (&mut anim_history).join() {
anim_history.time += dt.0 as f64;
}
}
}

View File

@ -71,7 +71,7 @@ impl<'a> System<'a> for Sys {
let time = if let Some((true, time)) =
last_history.map(|last| (last.current == animation, last.time))
{
time + dt.0 as f64
time
} else {
0.0
};

View File

@ -1,6 +1,7 @@
pub mod agent;
pub mod control;
pub mod phys;
pub mod anim;
// External
use specs::DispatcherBuilder;
@ -9,9 +10,11 @@ use specs::DispatcherBuilder;
const AGENT_SYS: &str = "agent_sys";
const CONTROL_SYS: &str = "control_sys";
const MOVEMENT_SYS: &str = "movement_sys";
const ANIM_SYS: &str = "anim_sys";
pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) {
dispatch_builder.add(agent::Sys, AGENT_SYS, &[]);
dispatch_builder.add(control::Sys, CONTROL_SYS, &[]);
dispatch_builder.add(phys::Sys, MOVEMENT_SYS, &[]);
dispatch_builder.add(anim::Sys, ANIM_SYS, &[]);
}

View File

@ -29,8 +29,8 @@ impl Animation for IdleAnimation {
let wave_dip = (wave_slow.abs() - 0.5).abs();
let head_look = Vec2::new(
(global_time as f32 / 5.0).floor().mul(7331.0).sin() * 0.5,
(global_time as f32 / 5.0).floor().mul(1337.0).sin() * 0.25,
((global_time + anim_time) as f32 / 5.0).floor().mul(7331.0).sin() * 0.5,
((global_time + anim_time) as f32 / 5.0).floor().mul(1337.0).sin() * 0.25,
);
next.head.offset = Vec3::new(5.5, 2.0, 11.5 + waveultra_slow * 0.4);
next.head.ori = Quaternion::rotation_z(head_look.x) * Quaternion::rotation_x(head_look.y);