veloren_voxygen_anim/biped_small/
ripostemelee.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedSmallSkeleton, SkeletonAttr, biped_small_wield_sword, init_biped_small_alpha,
4};
5use common::states::utils::StageSection;
6
7pub struct RiposteMeleeAnimation;
8impl Animation for RiposteMeleeAnimation {
9    type Dependency<'a> = (Option<&'a str>, StageSection);
10    type Skeleton = BipedSmallSkeleton;
11
12    #[cfg(feature = "use-dyn-lib")]
13    const UPDATE_FN: &'static [u8] = b"biped_small_riposte_melee\0";
14
15    #[cfg_attr(
16        feature = "be-dyn-lib",
17        unsafe(export_name = "biped_small_riposte_melee")
18    )]
19    fn update_skeleton_inner(
20        skeleton: &Self::Skeleton,
21        (ability_id, stage_section): Self::Dependency<'_>,
22        anim_time: f32,
23        rate: &mut f32,
24        s_a: &SkeletonAttr,
25    ) -> Self::Skeleton {
26        *rate = 1.0;
27        let mut next = (*skeleton).clone();
28
29        init_biped_small_alpha(&mut next, s_a);
30
31        match ability_id {
32            Some("common.abilities.haniwa.soldier.riposte") => {
33                let slow = (anim_time * 2.0).sin();
34                biped_small_wield_sword(&mut next, s_a, 0.0, slow);
35
36                let (move1, move2, move3) = match stage_section {
37                    StageSection::Buildup => (anim_time.powf(0.25), 0.0, 0.0),
38                    StageSection::Action => (1.0, anim_time, 0.0),
39                    StageSection::Recover => (1.0, 1.0, anim_time),
40                    _ => (0.0, 0.0, 0.0),
41                };
42                let pullback = 1.0 - move3;
43                let move1 = move1 * pullback;
44                let move2 = move2 * pullback;
45                let move2fast = move2.max(0.001).powf(0.25) * pullback;
46                let move2slow = move2.powi(4) * pullback;
47
48                next.detach_right = true;
49                // For some reason there's a discontinuity when using detach_right, two offsets
50                // below seem to help
51                next.control_r.position += next.control.position
52                    + Vec3::new(0.0, -2.0, 1.0)
53                    + Vec3::new(2.0 * move3, -1.0 * move3, 2.0 * move3);
54                next.control_r.orientation = next.control.orientation * next.control_r.orientation;
55
56                next.control.orientation.rotate_z(move1 * 1.9);
57                next.control.position += Vec3::new(0.0 * move1, 2.0 * move1, 13.0 * move1);
58                next.control.orientation.rotate_y(move1 * 2.7);
59
60                next.control.orientation.rotate_y(move2fast * -2.1);
61                next.control.orientation.rotate_z(move2 * -1.8);
62                next.control.orientation.rotate_x(move2slow * -3.2);
63                next.control.position += Vec3::new(move2 * 3.0, move2 * -2.0, move2 * -10.0);
64            },
65            _ => {},
66        }
67
68        next
69    }
70}