From 2451a64b9791ea221d9dc10dd7e7791af6b6c4e9 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Mon, 7 Sep 2020 01:14:39 -0400 Subject: [PATCH] stage 2 animation --- common/src/comp/inventory/item/tool.rs | 14 +- common/src/states/combo_melee.rs | 10 +- voxygen/src/anim/Cargo.toml | 2 +- voxygen/src/anim/src/character/alpha.rs | 5 +- voxygen/src/anim/src/character/spin.rs | 168 +++++++++++++++++------- voxygen/src/anim/src/character/wield.rs | 6 +- voxygen/src/scene/figure/mod.rs | 18 ++- 7 files changed, 156 insertions(+), 67 deletions(-) diff --git a/common/src/comp/inventory/item/tool.rs b/common/src/comp/inventory/item/tool.rs index 1cdc6716fa..f53f396ccc 100644 --- a/common/src/comp/inventory/item/tool.rs +++ b/common/src/comp/inventory/item/tool.rs @@ -127,8 +127,8 @@ impl Tool { knockback: 5.0, range: 3.5, angle: 45.0, - base_buildup_duration: Duration::from_millis(150), - base_recover_duration: Duration::from_millis(100), + base_buildup_duration: Duration::from_millis(10), + base_recover_duration: Duration::from_millis(10), }, combo_melee::Stage { stage: 2, @@ -138,8 +138,8 @@ impl Tool { knockback: 5.0, range: 3.5, angle: 45.0, - base_buildup_duration: Duration::from_millis(150), - base_recover_duration: Duration::from_millis(100), + base_buildup_duration: Duration::from_millis(1000), + base_recover_duration: Duration::from_millis(400), }, combo_melee::Stage { stage: 3, @@ -149,14 +149,14 @@ impl Tool { knockback: 5.0, range: 3.5, angle: 45.0, - base_buildup_duration: Duration::from_millis(150), - base_recover_duration: Duration::from_millis(100), + base_buildup_duration: Duration::from_millis(10), + base_recover_duration: Duration::from_millis(10), }, ], initial_energy_gain: 0, max_energy_gain: 100, energy_increase: 20, - combo_duration: Duration::from_millis(250), + combo_duration: Duration::from_millis(10), }, DashMelee { energy_cost: 700, diff --git a/common/src/states/combo_melee.rs b/common/src/states/combo_melee.rs index c1ad13d963..712c35cbfb 100644 --- a/common/src/states/combo_melee.rs +++ b/common/src/states/combo_melee.rs @@ -72,7 +72,9 @@ impl CharacterBehavior for Data { let stage_index = (self.stage - 1) as usize; - if self.stage_section == StageSection::Buildup && self.timer < self.stage_data[stage_index].base_buildup_duration { + if self.stage_section == StageSection::Buildup + && self.timer < self.stage_data[stage_index].base_buildup_duration + { // Build up update.character = CharacterState::ComboMelee(Data { stage: self.stage, @@ -116,7 +118,9 @@ impl CharacterBehavior for Data { timer: Duration::default(), stage_section: StageSection::Recover, }); - } else if self.stage_section == StageSection::Recover && self.timer < self.stage_data[stage_index].base_recover_duration { + } else if self.stage_section == StageSection::Recover + && self.timer < self.stage_data[stage_index].base_recover_duration + { update.character = CharacterState::ComboMelee(Data { stage: self.stage, num_stages: self.num_stages, @@ -173,7 +177,7 @@ impl CharacterBehavior for Data { .timer .checked_add(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), - stage_section: self.stage_section, + stage_section: self.stage_section, }); } } else { diff --git a/voxygen/src/anim/Cargo.toml b/voxygen/src/anim/Cargo.toml index 75bb0ecbe3..10869c6cc3 100644 --- a/voxygen/src/anim/Cargo.toml +++ b/voxygen/src/anim/Cargo.toml @@ -8,7 +8,7 @@ version = "0.7.0" name = "voxygen_anim" # Uncomment to use animation hot reloading # Note: this breaks `cargo test` -# crate-type = ["lib", "cdylib"] +crate-type = ["lib", "cdylib"] [features] be-dyn-lib = [] diff --git a/voxygen/src/anim/src/character/alpha.rs b/voxygen/src/anim/src/character/alpha.rs index f9cd1a33c5..71a23f05ed 100644 --- a/voxygen/src/anim/src/character/alpha.rs +++ b/voxygen/src/anim/src/character/alpha.rs @@ -2,7 +2,10 @@ use super::{ super::{vek::*, Animation}, CharacterSkeleton, SkeletonAttr, }; -use common::comp::item::{Hands, ToolKind}; +use common::{ + comp::item::{Hands, ToolKind}, + states::combo_melee::StageSection, +}; use std::f32::consts::PI; pub struct AlphaAnimation; diff --git a/voxygen/src/anim/src/character/spin.rs b/voxygen/src/anim/src/character/spin.rs index 8896e71bae..596906cdb3 100644 --- a/voxygen/src/anim/src/character/spin.rs +++ b/voxygen/src/anim/src/character/spin.rs @@ -2,7 +2,10 @@ use super::{ super::{vek::*, Animation}, CharacterSkeleton, SkeletonAttr, }; -use common::comp::item::{Hands, ToolKind}; +use common::{ + comp::item::{Hands, ToolKind}, + states::combo_melee::StageSection, +}; use std::f32::consts::PI; pub struct Input { @@ -11,7 +14,7 @@ pub struct Input { pub struct SpinAnimation; impl Animation for SpinAnimation { - type Dependency = (Option, Option, f64); + type Dependency = (Option, Option, f64, StageSection); type Skeleton = CharacterSkeleton; #[cfg(feature = "use-dyn-lib")] @@ -20,7 +23,7 @@ impl Animation for SpinAnimation { #[cfg_attr(feature = "be-dyn-lib", export_name = "character_spin")] fn update_skeleton_inner( skeleton: &Self::Skeleton, - (active_tool_kind, second_tool_kind, _global_time): Self::Dependency, + (active_tool_kind, second_tool_kind, _global_time, stage_section): Self::Dependency, anim_time: f64, rate: &mut f32, skeleton_attr: &SkeletonAttr, @@ -40,9 +43,83 @@ impl Animation for SpinAnimation { let spin = (anim_time as f32 * 2.8 * lab as f32).sin(); let spinhalf = (anim_time as f32 * 1.4 * lab as f32).sin(); - if let Some( - ToolKind::Axe(_) | ToolKind::Hammer(_) | ToolKind::Sword(_) | ToolKind::Dagger(_), - ) = active_tool_kind + let build = (anim_time as f32 * 8.0).sin(); + let recover = (anim_time as f32 * 8.0).sin(); + + let movement = anim_time as f32 * 1.0; + let test = (anim_time as f32 * 8.0).sin(); + let test2 = (anim_time as f32 * 1.0).sin(); + + if let Some(ToolKind::Sword(_)) = active_tool_kind { + next.l_hand.position = Vec3::new(-0.75, -1.0, 2.5); + next.l_hand.orientation = Quaternion::rotation_x(1.47) * Quaternion::rotation_y(-0.2); + next.l_hand.scale = Vec3::one() * 1.04; + next.r_hand.position = Vec3::new(0.75, -1.5, -0.5); + next.r_hand.orientation = Quaternion::rotation_x(1.47) * Quaternion::rotation_y(0.3); + next.r_hand.scale = Vec3::one() * 1.05; + next.main.position = Vec3::new(0.0, 0.0, 2.0); + next.main.orientation = Quaternion::rotation_x(-0.1) + * Quaternion::rotation_y(0.0) + * Quaternion::rotation_z(0.0); + + match stage_section { + StageSection::Buildup => { + //println!("{:.3} build", anim_time); + next.control.position = Vec3::new(5.0, 11.0 + build * 0.6, 2.0 + build * 0.6); + next.control.orientation = Quaternion::rotation_x(-1.57) + * Quaternion::rotation_y(2.8) + * Quaternion::rotation_z(1.0); + next.chest.orientation = Quaternion::rotation_y(movement * -0.1) + * Quaternion::rotation_z(build * 0.05 + movement * -0.6); + next.belt.orientation = Quaternion::rotation_x(movement * 0.1); + + next.shorts.orientation = Quaternion::rotation_x(movement * 0.1); + + next.head.orientation = Quaternion::rotation_y(movement * 0.1) + * Quaternion::rotation_z(movement * 0.4); + }, + StageSection::Swing => { + //println!("{:.3} swing", anim_time); + next.control.position = Vec3::new( + 7.0 + movement * -8.0, + 11.0 + test * 3.0, + 2.0 + test * 3.5 + movement * 3.0, + ); + next.control.orientation = + Quaternion::rotation_x(-1.57 + movement * -0.6 + test * -0.25) + * Quaternion::rotation_y(2.8 + movement * -2.0) + * Quaternion::rotation_z(1.0 + movement * 1.0); + next.head.orientation = Quaternion::rotation_z(-test * 0.8); + next.chest.orientation = Quaternion::rotation_x(test * 0.15) + * Quaternion::rotation_y(movement * 0.3) + * Quaternion::rotation_z(movement * 1.5); + next.belt.orientation = Quaternion::rotation_z(test2 * 0.5); + next.shorts.orientation = Quaternion::rotation_z(test2 * 1.5); + next.torso.orientation = Quaternion::rotation_z(test2 * 7.2); + }, + StageSection::Recover => { + //println!("{:.3} recover", anim_time); + next.control.position = Vec3::new( + -8.0, + 11.0 - recover * 0.8 + movement * -10.0, + 6.0 - recover * 0.4 + movement * -4.0, + ); + next.control.orientation = Quaternion::rotation_x(-1.57) + * Quaternion::rotation_y(0.0) + * Quaternion::rotation_z(1.0); + next.chest.orientation = Quaternion::rotation_y(movement * -0.1) + * Quaternion::rotation_z(movement * 0.4); + next.head.orientation = Quaternion::rotation_y(movement * 0.1) + * Quaternion::rotation_z(movement * -0.1); + }, + StageSection::Combo => { + //println!("{:.3} combo", anim_time); + }, + } + } + // println!("{:?}", stage_progress), + + if let Some(ToolKind::Axe(_) | ToolKind::Hammer(_) | ToolKind::Dagger(_)) = active_tool_kind { //INTENTION: SWORD next.l_hand.position = Vec3::new(-0.75, -1.0, -2.5); @@ -88,46 +165,47 @@ impl Animation for SpinAnimation { * Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0); next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; + + next.l_foot.position = + Vec3::new(-skeleton_attr.foot.0, foot * 1.0, skeleton_attr.foot.2); + next.l_foot.orientation = Quaternion::rotation_x(foot * -1.2); + next.l_foot.scale = Vec3::one(); + + next.r_foot.position = + Vec3::new(skeleton_attr.foot.0, foot * -1.0, skeleton_attr.foot.2); + next.r_foot.orientation = Quaternion::rotation_x(foot * 1.2); + next.r_foot.scale = Vec3::one(); + + next.l_shoulder.position = Vec3::new(-5.0, 0.0, 4.7); + next.l_shoulder.orientation = Quaternion::rotation_x(0.0); + next.l_shoulder.scale = Vec3::one() * 1.1; + + next.r_shoulder.position = Vec3::new(5.0, 0.0, 4.7); + next.r_shoulder.orientation = Quaternion::rotation_x(0.0); + next.r_shoulder.scale = Vec3::one() * 1.1; + + next.glider.position = Vec3::new(0.0, 5.0, 0.0); + next.glider.orientation = Quaternion::rotation_y(0.0); + next.glider.scale = Vec3::one() * 0.0; + + next.lantern.position = Vec3::new( + skeleton_attr.lantern.0, + skeleton_attr.lantern.1, + skeleton_attr.lantern.2, + ); + next.lantern.orientation = + Quaternion::rotation_x(spin * -0.7 + 0.4) * Quaternion::rotation_y(spin * 0.4); + next.lantern.scale = Vec3::one() * 0.65; + next.hold.scale = Vec3::one() * 0.0; + + next.l_control.position = Vec3::new(0.0, 0.0, 0.0); + next.l_control.orientation = Quaternion::rotation_x(0.0); + next.l_control.scale = Vec3::one(); + + next.r_control.position = Vec3::new(0.0, 0.0, 0.0); + next.r_control.orientation = Quaternion::rotation_x(0.0); + next.r_control.scale = Vec3::one(); } - - next.l_foot.position = Vec3::new(-skeleton_attr.foot.0, foot * 1.0, skeleton_attr.foot.2); - next.l_foot.orientation = Quaternion::rotation_x(foot * -1.2); - next.l_foot.scale = Vec3::one(); - - next.r_foot.position = Vec3::new(skeleton_attr.foot.0, foot * -1.0, skeleton_attr.foot.2); - next.r_foot.orientation = Quaternion::rotation_x(foot * 1.2); - next.r_foot.scale = Vec3::one(); - - next.l_shoulder.position = Vec3::new(-5.0, 0.0, 4.7); - next.l_shoulder.orientation = Quaternion::rotation_x(0.0); - next.l_shoulder.scale = Vec3::one() * 1.1; - - next.r_shoulder.position = Vec3::new(5.0, 0.0, 4.7); - next.r_shoulder.orientation = Quaternion::rotation_x(0.0); - next.r_shoulder.scale = Vec3::one() * 1.1; - - next.glider.position = Vec3::new(0.0, 5.0, 0.0); - next.glider.orientation = Quaternion::rotation_y(0.0); - next.glider.scale = Vec3::one() * 0.0; - - next.lantern.position = Vec3::new( - skeleton_attr.lantern.0, - skeleton_attr.lantern.1, - skeleton_attr.lantern.2, - ); - next.lantern.orientation = - Quaternion::rotation_x(spin * -0.7 + 0.4) * Quaternion::rotation_y(spin * 0.4); - next.lantern.scale = Vec3::one() * 0.65; - next.hold.scale = Vec3::one() * 0.0; - - next.l_control.position = Vec3::new(0.0, 0.0, 0.0); - next.l_control.orientation = Quaternion::rotation_x(0.0); - next.l_control.scale = Vec3::one(); - - next.r_control.position = Vec3::new(0.0, 0.0, 0.0); - next.r_control.orientation = Quaternion::rotation_x(0.0); - next.r_control.scale = Vec3::one(); - next.second.scale = match ( active_tool_kind.map(|tk| tk.hands()), second_tool_kind.map(|tk| tk.hands()), diff --git a/voxygen/src/anim/src/character/wield.rs b/voxygen/src/anim/src/character/wield.rs index 8ba6f64531..ad3761e3ad 100644 --- a/voxygen/src/anim/src/character/wield.rs +++ b/voxygen/src/anim/src/character/wield.rs @@ -111,18 +111,18 @@ impl Animation for WieldAnimation { match active_tool_kind { //TODO: Inventory Some(ToolKind::Sword(_)) => { - next.l_hand.position = Vec3::new(-0.75, -1.0, -2.5); + next.l_hand.position = Vec3::new(-0.75, -1.0, 2.5); next.l_hand.orientation = Quaternion::rotation_x(1.47) * Quaternion::rotation_y(-0.2); next.l_hand.scale = Vec3::one() * 1.04; - next.r_hand.position = Vec3::new(0.75, -1.5, -5.5); + next.r_hand.position = Vec3::new(0.75, -1.5, -0.5); next.r_hand.orientation = Quaternion::rotation_x(1.47) * Quaternion::rotation_y(0.3); next.r_hand.scale = Vec3::one() * 1.05; next.main.position = Vec3::new(0.0, 0.0, -3.0); next.main.orientation = Quaternion::rotation_x(-0.1); - next.control.position = Vec3::new(-7.0, 6.0, 6.0); + next.control.position = Vec3::new(-7.0, 7.0, 2.0); next.control.orientation = Quaternion::rotation_x(u_slow * 0.15) * Quaternion::rotation_z(u_slowalt * 0.08); next.control.scale = Vec3::one(); diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 31d78283b5..f210717cd1 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -915,11 +915,14 @@ impl FigureMgr { CharacterState::ComboMelee(s) => { let stage_index = (s.stage - 1) as usize; let stage_time = s.timer.as_secs_f64(); - let swing_frac = 0.5; // What percentage of buildup is swing animation + let swing_frac = 0.6; // What percentage of buildup is swing animation let mut stage_section = s.stage_section; let stage_progress = match s.stage_section { StageSection::Buildup => { - let buildup_progress = stage_time / s.stage_data[stage_index].base_buildup_duration.as_secs_f64(); + let buildup_progress = stage_time + / s.stage_data[stage_index] + .base_buildup_duration + .as_secs_f64(); if buildup_progress < swing_frac { buildup_progress / (1.0 - swing_frac) } else { @@ -928,11 +931,12 @@ impl FigureMgr { } }, StageSection::Recover => { - stage_time / s.stage_data[stage_index].base_recover_duration.as_secs_f64() - }, - StageSection::Combo => { - stage_time / s.combo_duration.as_secs_f64() + stage_time + / s.stage_data[stage_index] + .base_recover_duration + .as_secs_f64() }, + StageSection::Combo => stage_time / s.combo_duration.as_secs_f64(), _ => 0.0, }; match s.stage { @@ -945,7 +949,7 @@ impl FigureMgr { ), 2 => anim::character::SpinAnimation::update_skeleton( &target_base, - (active_tool_kind, second_tool_kind, time), + (active_tool_kind, second_tool_kind, time, stage_section), stage_progress, &mut state_animation_rate, skeleton_attr,