From e79cef4824a6178ae168abf93c865dc56d3ec45a Mon Sep 17 00:00:00 2001 From: jshipsey Date: Thu, 17 Sep 2020 00:18:09 -0400 Subject: [PATCH] dash animation --- common/src/comp/inventory/item/tool.rs | 8 +- common/src/states/spin_melee.rs | 19 +- voxygen/src/anim/src/character/alpha.rs | 8 +- voxygen/src/anim/src/character/beta.rs | 2 +- voxygen/src/anim/src/character/dash.rs | 203 ++++++++++++++------ voxygen/src/anim/src/character/spin.rs | 3 +- voxygen/src/anim/src/character/spinmelee.rs | 2 +- voxygen/src/anim/src/character/stand.rs | 4 +- voxygen/src/hud/skillbar.rs | 2 +- voxygen/src/scene/figure/mod.rs | 21 +- 10 files changed, 181 insertions(+), 91 deletions(-) diff --git a/common/src/comp/inventory/item/tool.rs b/common/src/comp/inventory/item/tool.rs index 9b481f6b30..0f2e0c7daf 100644 --- a/common/src/comp/inventory/item/tool.rs +++ b/common/src/comp/inventory/item/tool.rs @@ -127,8 +127,8 @@ impl Tool { knockback: 10.0, range: 4.0, angle: 30.0, - base_buildup_duration: Duration::from_millis(500), - base_swing_duration: Duration::from_millis(200), + base_buildup_duration: Duration::from_millis(350), + base_swing_duration: Duration::from_millis(100), base_recover_duration: Duration::from_millis(400), forward_movement: 0.5, }, @@ -176,7 +176,7 @@ impl Tool { angle: 45.0, energy_drain: 500, forward_speed: 4.0, - buildup_duration: Duration::from_millis(200), + buildup_duration: Duration::from_millis(250), charge_duration: Duration::from_millis(400), swing_duration: Duration::from_millis(100), recover_duration: Duration::from_millis(500), @@ -195,7 +195,7 @@ impl Tool { is_helicopter: false, forward_speed: 1.0, num_spins: 3, - } + }, ], Axe(_) => vec![ BasicMelee { diff --git a/common/src/states/spin_melee.rs b/common/src/states/spin_melee.rs index a25d148c87..f0a425bf5e 100644 --- a/common/src/states/spin_melee.rs +++ b/common/src/states/spin_melee.rs @@ -52,8 +52,7 @@ impl CharacterBehavior for Data { let mut update = StateUpdate::from(data); if self.static_data.is_helicopter { - update.vel.0 = - Vec3::new(data.inputs.move_dir.x, data.inputs.move_dir.y, 0.0) * 5.0; + update.vel.0 = Vec3::new(data.inputs.move_dir.x, data.inputs.move_dir.y, 0.0) * 5.0; } else { handle_orientation(data, &mut update, 1.0); forward_move(data, &mut update, 0.1, self.static_data.forward_speed); @@ -90,7 +89,7 @@ impl CharacterBehavior for Data { knockback: self.static_data.knockback, }); } else if self.stage_section == StageSection::Swing - && self.timer < self.static_data.swing_duration + && self.timer < self.static_data.swing_duration { // Swings update.character = CharacterState::SpinMelee(Data { @@ -111,7 +110,7 @@ impl CharacterBehavior for Data { stage_section: StageSection::Recover, }) } else if self.stage_section == StageSection::Recover - && self.timer < self.static_data.recover_duration + && self.timer < self.static_data.recover_duration { // Recover update.character = CharacterState::SpinMelee(Data { @@ -123,7 +122,10 @@ impl CharacterBehavior for Data { spins_remaining: self.spins_remaining, stage_section: self.stage_section, }) - } else if update.energy.current() >= self.static_data.energy_cost && (self.spins_remaining != 0 || (self.static_data.is_infinite && data.inputs.secondary.is_pressed())) { + } else if update.energy.current() >= self.static_data.energy_cost + && (self.spins_remaining != 0 + || (self.static_data.is_infinite && data.inputs.secondary.is_pressed())) + { let new_spins_remaining = if self.static_data.is_infinite { self.spins_remaining } else { @@ -136,9 +138,10 @@ impl CharacterBehavior for Data { stage_section: StageSection::Buildup, }); // Consumes energy if there's enough left and RMB is held down - update - .energy - .change_by(-(self.static_data.energy_cost as i32), EnergySource::Ability); + update.energy.change_by( + -(self.static_data.energy_cost as i32), + EnergySource::Ability, + ); } else { // Done update.character = CharacterState::Wielding; diff --git a/voxygen/src/anim/src/character/alpha.rs b/voxygen/src/anim/src/character/alpha.rs index 9bfef6bfcb..3bd7971070 100644 --- a/voxygen/src/anim/src/character/alpha.rs +++ b/voxygen/src/anim/src/character/alpha.rs @@ -84,10 +84,8 @@ impl Animation for AlphaAnimation { next.main.orientation = Quaternion::rotation_x(-0.1) * Quaternion::rotation_y(0.0) * Quaternion::rotation_z(0.0); - - next.head.position = Vec3::new(0.0, skeleton_attr.head.0+0.0, skeleton_attr.head.1); - + next.head.position = Vec3::new(0.0, skeleton_attr.head.0 + 0.0, skeleton_attr.head.1); if let Some(stage_section) = stage_section { match stage_section { @@ -133,8 +131,8 @@ impl Animation for AlphaAnimation { next.chest.orientation = Quaternion::rotation_y(0.0) * Quaternion::rotation_z(-1.57 + movement * 0.5); - next.head.orientation = - Quaternion::rotation_y(0.0) * Quaternion::rotation_z(1.57+movement*-0.5); + next.head.orientation = Quaternion::rotation_y(0.0) + * Quaternion::rotation_z(1.57 + movement * -0.5); }, _ => {}, } diff --git a/voxygen/src/anim/src/character/beta.rs b/voxygen/src/anim/src/character/beta.rs index 212d3fd0d1..3570327a0c 100644 --- a/voxygen/src/anim/src/character/beta.rs +++ b/voxygen/src/anim/src/character/beta.rs @@ -69,7 +69,7 @@ impl Animation for BetaAnimation { * Quaternion::rotation_y(0.0) * Quaternion::rotation_z(0.0); - next.head.position = Vec3::new(0.0, skeleton_attr.head.0, skeleton_attr.head.1); + next.head.position = Vec3::new(0.0, skeleton_attr.head.0, skeleton_attr.head.1); if let Some(stage_section) = stage_section { match stage_section { diff --git a/voxygen/src/anim/src/character/dash.rs b/voxygen/src/anim/src/character/dash.rs index 60643bfcac..9d15e0514c 100644 --- a/voxygen/src/anim/src/character/dash.rs +++ b/voxygen/src/anim/src/character/dash.rs @@ -6,6 +6,7 @@ use common::{ comp::item::{Hands, ToolKind}, states::utils::StageSection, }; +use std::f32::consts::PI; pub struct Input { pub attack: bool, @@ -37,67 +38,150 @@ impl Animation for DashAnimation { let mut next = (*skeleton).clone(); let lab = 1.0; - let foot = (((5.0) - / (1.1 + 3.9 * ((anim_time as f32 * lab as f32 * 25.0).sin()).powf(2.0 as f32))) - .sqrt()) - * ((anim_time as f32 * lab as f32 * 25.0).sin()); - let slow = (((5.0) / (1.1 + 3.9 * ((anim_time as f32 * lab as f32 * 12.4).sin()).powf(2.0 as f32))) .sqrt()) * ((anim_time as f32 * lab as f32 * 12.4).sin()); + let short = (((5.0) + / (1.5 + 3.5 * ((anim_time as f32 * lab as f32 * 5.0).sin()).powf(2.0 as f32))) + .sqrt()) + * ((anim_time as f32 * lab as f32 * 5.0).sin()); + let foothoril = (anim_time as f32 * 5.0 * lab as f32 + PI * 1.45).sin(); + let foothorir = (anim_time as f32 * 5.0 * lab as f32 + PI * (0.45)).sin(); + + let footvertl = (anim_time as f32 * 5.0 * lab as f32).sin(); + let footvertr = (anim_time as f32 * 5.0 * lab as f32 + PI).sin(); + + let footrotl = (((1.0) + / (0.05 + + (0.95) + * ((anim_time as f32 * 5.0 * lab as f32 + PI * 1.4).sin()).powf(2.0 as f32))) + .sqrt()) + * ((anim_time as f32 * 5.0 * lab as f32 + PI * 1.4).sin()); + + let footrotr = (((1.0) + / (0.05 + + (0.95) + * ((anim_time as f32 * 5.0 * lab as f32 + PI * 0.4).sin()).powf(2.0 as f32))) + .sqrt()) + * ((anim_time as f32 * 5.0 * lab as f32 + PI * 0.4).sin()); + + let shortalt = (anim_time as f32 * lab as f32 * 5.0 + PI / 2.0).sin(); + + let movement = (anim_time as f32 * 1.0).min(1.0); + + next.head.position = Vec3::new(0.0, -2.0 + skeleton_attr.head.0, skeleton_attr.head.1); + + 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 active_tool_kind { //TODO: Inventory Some(ToolKind::Sword(_)) => { if let Some(stage_section) = stage_section { match stage_section { - StageSection::Buildup => {}, - StageSection::Charge => {}, - StageSection::Swing => {}, - StageSection::Recover => {}, + StageSection::Buildup => { + next.head.orientation = Quaternion::rotation_z(movement * -0.9); + + next.chest.orientation = Quaternion::rotation_z(movement * 1.1); + + next.control.position = Vec3::new(-7.0 + movement * -5.0, 7.0, 2.0); + next.control.orientation = Quaternion::rotation_x(movement * -1.0) + * Quaternion::rotation_y(movement * 1.5) + * Quaternion::rotation_z(0.0); + next.control.scale = Vec3::one(); + next.l_foot.position = Vec3::new( + -skeleton_attr.foot.0, + skeleton_attr.foot.1 + movement * -12.0, + skeleton_attr.foot.2, + ); + next.l_foot.orientation = Quaternion::rotation_x(movement * -1.0); + next.r_foot.position = Vec3::new( + skeleton_attr.foot.0, + skeleton_attr.foot.1, + skeleton_attr.foot.2, + ); + }, + StageSection::Charge => { + next.head.position = Vec3::new( + 0.0, + -2.0 + skeleton_attr.head.0, + skeleton_attr.head.1 + movement * 1.0, + ); + + next.head.orientation = Quaternion::rotation_x(0.0) + * Quaternion::rotation_y(movement * -0.3) + * Quaternion::rotation_z(-0.9 + movement * -0.2 + short * -0.05); + next.chest.position = Vec3::new( + 0.0, + skeleton_attr.chest.0, + skeleton_attr.chest.1 + 2.0 + shortalt * -2.5, + ); + + next.chest.orientation = Quaternion::rotation_x(movement * -0.4) + * Quaternion::rotation_y(movement * -0.2) + * Quaternion::rotation_z(1.1); + + next.control.position = + Vec3::new(-13.0, 7.0 + movement * -2.0, 2.0 + movement * 2.0); + next.control.orientation = + Quaternion::rotation_x(-1.0) * Quaternion::rotation_y(1.5); + next.control.scale = Vec3::one(); + + next.shorts.orientation = Quaternion::rotation_z(short * 0.25); + next.belt.orientation = Quaternion::rotation_z(short * 0.1); + next.l_foot.position = Vec3::new( + 2.0 - skeleton_attr.foot.0, + skeleton_attr.foot.1 + foothoril * -7.5, + 2.0 + skeleton_attr.foot.2 + ((footvertl * -4.0).max(-1.0)), + ); + next.l_foot.orientation = + Quaternion::rotation_x(-0.6 + footrotl * -0.6) + * Quaternion::rotation_z(-0.2); + + next.r_foot.position = Vec3::new( + 2.0 + skeleton_attr.foot.0, + skeleton_attr.foot.1 + foothorir * -7.5, + 2.0 + skeleton_attr.foot.2 + ((footvertr * -4.0).max(-1.0)), + ); + next.r_foot.orientation = + Quaternion::rotation_x(-0.6 + footrotr * -0.6) + * Quaternion::rotation_z(-0.2); + }, + StageSection::Swing => { + next.head.orientation = Quaternion::rotation_y(0.2 + movement * -0.2) + * Quaternion::rotation_z(-1.1 + movement * 1.8); + + next.chest.orientation = Quaternion::rotation_y(-0.2 + movement * 0.3) + * Quaternion::rotation_z(1.1 + movement * -2.2); + + next.control.position = Vec3::new(-13.0 + movement * -2.0, 5.0, 4.0); + next.control.orientation = + Quaternion::rotation_x(-1.0 + movement * -0.5) + * Quaternion::rotation_y(1.5 + movement * -2.5); + next.control.scale = Vec3::one(); + }, + StageSection::Recover => { + next.head.orientation = Quaternion::rotation_z(0.7); + + next.chest.orientation = Quaternion::rotation_z(-1.1); + + next.control.position = Vec3::new(-15.0, 5.0, 2.0); + next.control.orientation = + Quaternion::rotation_x(-1.5) * Quaternion::rotation_y(-1.0); + next.control.scale = Vec3::one(); + }, } } - - next.head.position = Vec3::new( - 0.0, - -2.0 + skeleton_attr.head.0, - -2.0 + skeleton_attr.head.1, - ); - next.head.orientation = Quaternion::rotation_z(0.0) - * Quaternion::rotation_x(0.0) - * Quaternion::rotation_y(0.0); - next.head.scale = Vec3::one() * skeleton_attr.head_scale; - - next.chest.position = Vec3::new(0.0, 0.0, 7.0 + slow * 2.0); - next.chest.orientation = - Quaternion::rotation_x(-0.5) * Quaternion::rotation_z(-0.7); - - next.belt.position = Vec3::new(0.0, 1.0, -1.0); - next.belt.orientation = Quaternion::rotation_x(0.2) * Quaternion::rotation_z(0.2); - - next.shorts.position = Vec3::new(0.0, 3.0, -3.0); - next.shorts.orientation = Quaternion::rotation_x(0.4) * Quaternion::rotation_z(0.3); - - next.l_hand.position = Vec3::new(-0.75, -1.0, -2.5); - next.l_hand.orientation = Quaternion::rotation_x(1.27); - next.l_hand.scale = Vec3::one() * 1.04; - next.r_hand.position = Vec3::new(0.75, -1.5, -5.5); - next.r_hand.orientation = Quaternion::rotation_x(1.27); - next.r_hand.scale = Vec3::one() * 1.05; - next.main.position = Vec3::new(0.0, 6.0, -1.0); - next.main.orientation = Quaternion::rotation_x(-0.3); - next.main.scale = Vec3::one(); - - next.control.position = Vec3::new(-8.0 - slow * 0.5, 3.0 - foot * 0.6, 3.0); - next.control.orientation = - Quaternion::rotation_x(-0.3) * Quaternion::rotation_z(1.1 + slow * 0.2); - next.control.scale = Vec3::one(); - next.l_foot.position = Vec3::new(-1.4, foot * 3.0 + 2.0, skeleton_attr.foot.2); - next.l_foot.orientation = Quaternion::rotation_x(foot * -0.4 - 0.8); - - next.r_foot.position = Vec3::new(5.4, foot * -3.0 - 1.0, skeleton_attr.foot.2); - next.r_foot.orientation = Quaternion::rotation_x(foot * 0.4 - 0.8); }, Some(ToolKind::Dagger(_)) => { next.head.position = Vec3::new( @@ -130,15 +214,15 @@ impl Animation for DashAnimation { next.main.orientation = Quaternion::rotation_x(-0.3); next.main.scale = Vec3::one(); - next.control.position = Vec3::new(-8.0 - slow * 0.5, 3.0 - foot * 0.6, 3.0); + next.control.position = Vec3::new(-8.0 - slow * 0.5, 3.0, 3.0); next.control.orientation = Quaternion::rotation_x(-0.3) * Quaternion::rotation_z(1.1 + slow * 0.2); next.control.scale = Vec3::one(); - next.l_foot.position = Vec3::new(-1.4, foot * 3.0 + 2.0, skeleton_attr.foot.2); - next.l_foot.orientation = Quaternion::rotation_x(foot * -0.4 - 0.8); + next.l_foot.position = Vec3::new(-1.4, 2.0, skeleton_attr.foot.2); + next.l_foot.orientation = Quaternion::rotation_x(-0.8); - next.r_foot.position = Vec3::new(5.4, foot * -3.0 - 1.0, skeleton_attr.foot.2); - next.r_foot.orientation = Quaternion::rotation_x(foot * 0.4 - 0.8); + next.r_foot.position = Vec3::new(5.4, -1.0, skeleton_attr.foot.2); + next.r_foot.orientation = Quaternion::rotation_x(-0.8); }, _ => {}, } @@ -189,11 +273,11 @@ impl Animation for DashAnimation { next.second.orientation = Quaternion::rotation_x(-0.3); next.second.scale = Vec3::one(); - next.l_foot.position = Vec3::new(-1.4, foot * 3.0 + 2.0, skeleton_attr.foot.2); - next.l_foot.orientation = Quaternion::rotation_x(foot * -0.4 - 0.8); + next.l_foot.position = Vec3::new(-1.4, 2.0, skeleton_attr.foot.2); + next.l_foot.orientation = Quaternion::rotation_x(-0.8); - next.r_foot.position = Vec3::new(5.4, foot * -3.0 - 1.0, skeleton_attr.foot.2); - next.r_foot.orientation = Quaternion::rotation_x(foot * 0.4 - 0.8); + next.r_foot.position = Vec3::new(5.4, -1.0, skeleton_attr.foot.2); + next.r_foot.orientation = Quaternion::rotation_x(-0.8); }, _ => {}, } @@ -207,9 +291,6 @@ impl Animation for DashAnimation { Quaternion::rotation_x(slow * -0.7 + 0.4) * Quaternion::rotation_y(slow * 0.4); next.hold.scale = Vec3::one() * 0.0; - next.torso.position = Vec3::new(0.0, 0.0, 0.1) * skeleton_attr.scaler; - next.torso.orientation = - Quaternion::rotation_z(0.0) * Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0); next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; next.l_control.scale = Vec3::one(); diff --git a/voxygen/src/anim/src/character/spin.rs b/voxygen/src/anim/src/character/spin.rs index 21789934e9..ed8d1b5ed1 100644 --- a/voxygen/src/anim/src/character/spin.rs +++ b/voxygen/src/anim/src/character/spin.rs @@ -54,9 +54,8 @@ impl Animation for SpinAnimation { 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(); - - next.head.position = Vec3::new(0.0, skeleton_attr.head.0, skeleton_attr.head.1); + next.head.position = Vec3::new(0.0, skeleton_attr.head.0, skeleton_attr.head.1); if let Some(ToolKind::Sword(_)) = active_tool_kind { next.l_hand.position = Vec3::new(-0.75, -1.0, 2.5); diff --git a/voxygen/src/anim/src/character/spinmelee.rs b/voxygen/src/anim/src/character/spinmelee.rs index 1e350418c6..7de89ae8d9 100644 --- a/voxygen/src/anim/src/character/spinmelee.rs +++ b/voxygen/src/anim/src/character/spinmelee.rs @@ -68,7 +68,7 @@ impl Animation for SpinMeleeAnimation { _ => {}, } } - } + }, Some(ToolKind::Axe(_)) => { next.l_hand.position = Vec3::new(-0.5, 0.0, 4.0); next.l_hand.orientation = Quaternion::rotation_x(PI / 2.0) diff --git a/voxygen/src/anim/src/character/stand.rs b/voxygen/src/anim/src/character/stand.rs index 3362bd4ea2..67225246f2 100644 --- a/voxygen/src/anim/src/character/stand.rs +++ b/voxygen/src/anim/src/character/stand.rs @@ -41,7 +41,7 @@ impl Animation for StandAnimation { ); next.head.position = Vec3::new( 0.0, - -3.0 + skeleton_attr.head.0, + -2.0 + skeleton_attr.head.0, skeleton_attr.head.1 + slow * 0.3 + breathe * -0.05, ); next.head.orientation = Quaternion::rotation_z(head_look.x) @@ -174,7 +174,7 @@ impl Animation for StandAnimation { next.lantern.orientation = Quaternion::rotation_x(0.1) * Quaternion::rotation_y(0.1); next.lantern.scale = Vec3::one() * 0.65; - next.torso.position = Vec3::new(0.0, 0.0, 0.) * skeleton_attr.scaler; + next.torso.position = Vec3::new(0.0, 0.0, 0.0) * skeleton_attr.scaler; next.torso.orientation = Quaternion::rotation_x(0.0); next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index 215a0fe37c..9b83cb5e43 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -805,7 +805,7 @@ impl<'a> Widget for Skillbar<'a> { )), ToolKind::Sword(_) => Some(( "Whirlwind", - "\nMove forward while spinning with \n your sword." + "\nMove forward while spinning with \n your sword.", )), ToolKind::Debug(kind) => match kind.as_ref() { "Boost" => Some(( diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 45b217454d..52228dd073 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -25,8 +25,9 @@ use anim::{ }; use common::{ comp::{ - item::{ItemKind, ToolKind}, Body, CharacterState, Item, Last, LightAnimation, LightEmitter, Loadout, - Ori, PhysicsState, Pos, Scale, Stats, Vel, + item::{ItemKind, ToolKind}, + Body, CharacterState, Item, Last, LightAnimation, LightEmitter, Loadout, Ori, PhysicsState, + Pos, Scale, Stats, Vel, }, span, state::{DeltaTime, State}, @@ -941,23 +942,31 @@ impl FigureMgr { let stage_time = s.timer.as_secs_f64(); match s.stage_section { StageSection::Buildup => { - stage_time / s.static_data.buildup_duration.as_secs_f64() + stage_time + / s.static_data.buildup_duration.as_secs_f64() }, StageSection::Swing => { stage_time / s.static_data.swing_duration.as_secs_f64() }, StageSection::Recover => { - stage_time / s.static_data.recover_duration.as_secs_f64() + stage_time + / s.static_data.recover_duration.as_secs_f64() }, _ => 0.0, } }, - _ => state.state_time + _ => state.state_time, }; anim::character::SpinMeleeAnimation::update_skeleton( &target_base, - (active_tool_kind, second_tool_kind, vel.0, time, Some(s.stage_section),), + ( + active_tool_kind, + second_tool_kind, + vel.0, + time, + Some(s.stage_section), + ), stage_progress, &mut state_animation_rate, skeleton_attr,