veloren_voxygen_anim/character/
jump.rs1use super::{
2 super::{Animation, vek::*},
3 CharacterSkeleton, SkeletonAttr,
4};
5use common::comp::item::{Hands, ToolKind};
6
7pub struct JumpAnimation;
8impl Animation for JumpAnimation {
9 type Dependency<'a> = (
10 Option<ToolKind>,
11 Option<ToolKind>,
12 (Option<Hands>, Option<Hands>),
13 Vec3<f32>,
14 Vec3<f32>,
15 Vec3<f32>,
16 f32,
17 );
18 type Skeleton = CharacterSkeleton;
19
20 #[cfg(feature = "use-dyn-lib")]
21 const UPDATE_FN: &'static [u8] = b"character_jump\0";
22
23 #[cfg_attr(feature = "be-dyn-lib", export_name = "character_jump")]
24
25 fn update_skeleton_inner(
26 skeleton: &Self::Skeleton,
27 (active_tool_kind, second_tool_kind, hands, velocity, orientation, last_ori, global_time): Self::Dependency<'_>,
28 anim_time: f32,
29 _rate: &mut f32,
30 s_a: &SkeletonAttr,
31 ) -> Self::Skeleton {
32 let mut next = (*skeleton).clone();
33 let slow = (anim_time * 7.0).sin();
34
35 let subtract = global_time - anim_time;
36 let check = subtract - subtract.trunc();
37 let switch = (check - 0.5).signum();
38
39 let falling = (velocity.z * 0.1).clamped(-1.0, 1.0);
40 let speed = Vec2::<f32>::from(velocity).magnitude();
41 let speednorm = (speed / 10.0).min(1.0);
42
43 let ori: Vec2<f32> = Vec2::from(orientation);
44 let last_ori = Vec2::from(last_ori);
45 let tilt = if vek::Vec2::new(ori, last_ori)
46 .map(|o| o.magnitude_squared())
47 .map(|m| m > 0.001 && m.is_finite())
48 .reduce_and()
49 && ori.angle_between(last_ori).is_finite()
50 {
51 ori.angle_between(last_ori).min(0.2)
52 * last_ori.determine_side(Vec2::zero(), ori).signum()
53 } else {
54 0.0
55 } * 1.3;
56 next.head.scale = Vec3::one() * s_a.head_scale;
57 next.shoulder_l.scale = Vec3::one() * 1.1;
58 next.shoulder_r.scale = Vec3::one() * 1.1;
59 next.back.scale = Vec3::one() * 1.02;
60
61 next.head.position = Vec3::new(0.0, s_a.head.0, -1.0 + s_a.head.1);
62 next.head.orientation =
63 Quaternion::rotation_x(0.25 + slow * 0.04) * Quaternion::rotation_z(tilt * -2.5);
64
65 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + 1.0);
66 next.chest.orientation =
67 Quaternion::rotation_x(speednorm * -0.3) * Quaternion::rotation_z(tilt * -2.0);
68
69 next.belt.position = Vec3::new(
70 0.0,
71 s_a.belt.0 + speednorm * 1.2,
72 s_a.belt.1 + speednorm * 1.0,
73 );
74 next.belt.orientation =
75 Quaternion::rotation_x(speednorm * 0.3) * Quaternion::rotation_z(tilt * 2.0);
76
77 next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
78 next.back.orientation = Quaternion::rotation_z(0.0);
79
80 next.shorts.position = Vec3::new(
81 0.0,
82 s_a.shorts.0 + speednorm * 3.0,
83 s_a.shorts.1 + speednorm * 2.0,
84 );
85 next.shorts.orientation =
86 Quaternion::rotation_x(speednorm * 0.5) * Quaternion::rotation_z(tilt * 3.0);
87
88 if switch > 0.0 {
89 next.hand_l.position = Vec3::new(
90 -s_a.hand.0,
91 1.0 + s_a.hand.1 + 4.0,
92 2.0 + s_a.hand.2 + slow * 1.5,
93 );
94 next.hand_l.orientation =
95 Quaternion::rotation_x(1.9 + slow * 0.4) * Quaternion::rotation_y(0.2);
96
97 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1 - 3.0, s_a.hand.2 + slow * 1.5);
98 next.hand_r.orientation =
99 Quaternion::rotation_x(-0.5 + slow * -0.4) * Quaternion::rotation_y(-0.2);
100 } else {
101 next.hand_l.position =
102 Vec3::new(-s_a.hand.0, s_a.hand.1 - 3.0, s_a.hand.2 + slow * 1.5);
103 next.hand_l.orientation =
104 Quaternion::rotation_x(-0.5 + slow * -0.4) * Quaternion::rotation_y(0.2);
105
106 next.hand_r.position = Vec3::new(
107 s_a.hand.0,
108 1.0 + s_a.hand.1 + 4.0,
109 2.0 + s_a.hand.2 + slow * 1.5,
110 );
111 next.hand_r.orientation =
112 Quaternion::rotation_x(1.9 + slow * 0.4) * Quaternion::rotation_y(-0.2);
113 };
114
115 next.foot_l.position = Vec3::new(
116 -s_a.foot.0,
117 s_a.foot.1 - 5.0 * switch,
118 2.0 + s_a.foot.2 + slow * 1.5 + falling * -2.0,
119 );
120 next.foot_l.orientation = Quaternion::rotation_x(-0.8 * switch + slow * -0.2 * switch);
121
122 next.foot_r.position = Vec3::new(
123 s_a.foot.0,
124 s_a.foot.1 + 5.0 * switch,
125 2.0 + s_a.foot.2 + slow * 1.5 + falling * -2.0,
126 );
127 next.foot_r.orientation = Quaternion::rotation_x(0.8 * switch + slow * 0.2 * switch);
128
129 next.shoulder_l.position = Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
130 next.shoulder_l.orientation = Quaternion::rotation_x(0.4 * switch);
131
132 next.shoulder_r.position = Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
133 next.shoulder_r.orientation = Quaternion::rotation_x(-0.4 * switch);
134
135 next.glider.position = Vec3::new(0.0, 0.0, 10.0);
136 next.glider.scale = Vec3::one() * 0.0;
137
138 next.do_tools_on_back(hands, active_tool_kind, second_tool_kind);
139
140 next.do_hold_lantern(s_a, anim_time, anim_time, speednorm, 0.0, tilt);
141
142 next.torso.position = Vec3::new(0.0, 0.0, 0.0);
143 next.torso.orientation = Quaternion::rotation_x(0.0);
144
145 next
146 }
147}