From cfbf69ae893323e2833453b9107c59d817840e13 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Mon, 30 Dec 2019 15:16:21 +0000 Subject: [PATCH] Made rolling less slippy, added tilt --- common/src/sys/movement.rs | 10 ++++++++-- voxygen/src/anim/character/roll.rs | 20 +++++++++++++++++--- voxygen/src/anim/character/run.rs | 1 - voxygen/src/scene/figure/mod.rs | 2 +- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/common/src/sys/movement.rs b/common/src/sys/movement.rs index 4c85dfc8cc..31553d3d07 100644 --- a/common/src/sys/movement.rs +++ b/common/src/sys/movement.rs @@ -1,7 +1,8 @@ use super::phys::GRAVITY; use crate::{ comp::{ - CharacterState, Controller, Mounting, MovementState::*, Ori, PhysicsState, Pos, Stats, Vel, + ActionState, CharacterState, Controller, Mounting, MovementState::*, Ori, PhysicsState, + Pos, Stats, Vel, }, event::{EventBus, ServerEvent}, state::DeltaTime, @@ -180,7 +181,12 @@ impl<'a> System<'a> for Sys { // producing potentially unexpected changes in direction Vec2::from(vel.0) } else { - Vec2::from(inputs.move_dir) + if let ActionState::Roll { .. } = character.action { + // So can can't spin/slip around while rolling + Vec2::from(vel.0) + } else { + Vec2::from(inputs.move_dir) + } }; if ori_dir.magnitude_squared() > 0.0001 diff --git a/voxygen/src/anim/character/roll.rs b/voxygen/src/anim/character/roll.rs index 92e6149e2e..2e76022b01 100644 --- a/voxygen/src/anim/character/roll.rs +++ b/voxygen/src/anim/character/roll.rs @@ -10,11 +10,11 @@ pub struct RollAnimation; impl Animation for RollAnimation { type Skeleton = CharacterSkeleton; - type Dependency = (Option, f64); + type Dependency = (Option, Vec3, Vec3, f64); fn update_skeleton( skeleton: &Self::Skeleton, - (_active_tool_kind, _global_time): Self::Dependency, + (_active_tool_kind, orientation, last_ori, _global_time): Self::Dependency, anim_time: f64, _rate: &mut f32, skeleton_attr: &SkeletonAttr, @@ -27,6 +27,20 @@ impl Animation for RollAnimation { let wave_slow = (anim_time as f32 * 2.8 + PI).sin(); let wave_dub = (anim_time as f32 * 5.5).sin(); + let ori = Vec2::from(orientation); + let last_ori = Vec2::from(last_ori); + let tilt = if Vec2::new(ori, last_ori) + .map(|o| Vec2::::from(o).magnitude_squared()) + .map(|m| m > 0.001 && m.is_finite()) + .reduce_and() + && ori.angle_between(last_ori).is_finite() + { + ori.angle_between(last_ori).min(0.5) + * last_ori.determine_side(Vec2::zero(), ori).signum() + } else { + 0.0 + } * 1.3; + next.head.offset = Vec3::new( 0.0 + skeleton_attr.neck_right, -2.0 + skeleton_attr.neck_forward, @@ -102,7 +116,7 @@ impl Animation for RollAnimation { next.torso.offset = Vec3::new(0.0, 11.0, 0.1 + wave_dub * 16.0) / 11.0 * skeleton_attr.scaler; - next.torso.ori = Quaternion::rotation_x(wave_slow * 6.5); + next.torso.ori = Quaternion::rotation_x(wave_slow * 6.5) * Quaternion::rotation_y(tilt); next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; next } diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index 38fdc58728..4e5ae350d6 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -56,7 +56,6 @@ impl Animation for RunAnimation { let ori = Vec2::from(orientation); let last_ori = Vec2::from(last_ori); - let tilt = if Vec2::new(ori, last_ori) .map(|o| Vec2::::from(o).magnitude_squared()) .map(|m| m > 0.001 && m.is_finite()) diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index b5e33ee35d..a5f88385d7 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -280,7 +280,7 @@ impl FigureMgr { ), (_, Roll { .. }) => anim::character::RollAnimation::update_skeleton( &target_base, - (active_tool_kind, time), + (active_tool_kind, ori.0, state.last_ori, time), state.action_time, &mut action_animation_rate, skeleton_attr,