veloren_voxygen_anim/crustacean/
stunned.rs1use super::{
2 super::{Animation, vek::*},
3 CrustaceanSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6
7pub struct StunnedAnimation;
8
9impl Animation for StunnedAnimation {
10 type Dependency<'a> = (f32, f32, Option<StageSection>, f32);
11 type Skeleton = CrustaceanSkeleton;
12
13 #[cfg(feature = "use-dyn-lib")]
14 const UPDATE_FN: &'static [u8] = b"crustacean_stunned\0";
15
16 #[cfg_attr(feature = "be-dyn-lib", export_name = "crustacean_stunned")]
17 fn update_skeleton_inner(
18 skeleton: &Self::Skeleton,
19 (_velocity, global_time, stage_section, timer): Self::Dependency<'_>,
20 anim_time: f32,
21 _rate: &mut f32,
22 s_a: &SkeletonAttr,
23 ) -> Self::Skeleton {
24 let mut next = (*skeleton).clone();
25
26 let (_movement1base, movement2, twitch) = match stage_section {
27 Some(StageSection::Buildup) => (anim_time.powf(0.1), 0.0, anim_time),
28 Some(StageSection::Recover) => (1.0, anim_time.powf(4.0), 1.0),
29 _ => (0.0, 0.0, 0.0),
30 };
31
32 let pullback = (1.0 - movement2) * 0.1;
33
34 let subtract = global_time - timer;
35 let check = subtract - subtract.trunc();
36 let mirror = (check - 0.5).signum();
37 let twitch1 = mirror * (twitch * 5.0).cos() * pullback;
38 let twitch2 = mirror * (twitch * 5.0).sin() * pullback;
39
40 next.chest.scale = Vec3::one() * s_a.scaler;
41
42 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1);
43
44 next.arm_l.orientation = Quaternion::rotation_x(-twitch2 * 1.2);
45 next.arm_r.orientation = Quaternion::rotation_x(twitch2 * 1.2);
46 next.pincer_l1.orientation = Quaternion::rotation_z(0.17);
47 next.pincer_r1.orientation = Quaternion::rotation_z(-0.17);
48
49 next.leg_fl.position = Vec3::new(-s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
50 next.leg_fr.position = Vec3::new(s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
51 next.leg_fl.orientation =
52 Quaternion::rotation_z(s_a.leg_ori.0) * Quaternion::rotation_x(twitch1 * 0.8 + 0.4);
53 next.leg_fr.orientation =
54 Quaternion::rotation_z(-s_a.leg_ori.0) * Quaternion::rotation_x(-twitch1 * 0.8 - 0.4);
55
56 next.leg_cl.position = Vec3::new(-s_a.leg_c.0, s_a.leg_c.1, s_a.leg_c.2);
57 next.leg_cr.position = Vec3::new(s_a.leg_c.0, s_a.leg_c.1, s_a.leg_c.2);
58 next.leg_cl.orientation =
59 Quaternion::rotation_z(s_a.leg_ori.1) * Quaternion::rotation_y(twitch2 * 0.4 + 0.4);
60 next.leg_cr.orientation =
61 Quaternion::rotation_z(-s_a.leg_ori.1) * Quaternion::rotation_y(-twitch2 * 0.4 - 0.4);
62
63 next.leg_bl.position = Vec3::new(-s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
64 next.leg_br.position = Vec3::new(s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
65 next.leg_bl.orientation =
66 Quaternion::rotation_z(s_a.leg_ori.2) * Quaternion::rotation_y(twitch2 * 0.4 + 0.4);
67 next.leg_br.orientation =
68 Quaternion::rotation_z(-s_a.leg_ori.2) * Quaternion::rotation_y(-twitch2 * 0.4 - 0.4);
69
70 next
71 }
72}