@@ -67,6 +67,7 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
67
67
m_view_bobbing_anim(0 ),
68
68
m_view_bobbing_state(0 ),
69
69
m_view_bobbing_speed(0 ),
70
+ m_view_bobbing_fall(0 ),
70
71
71
72
m_digging_anim(0 ),
72
73
m_digging_button(-1 ),
@@ -134,6 +135,13 @@ inline f32 my_modf(f32 x)
134
135
135
136
void Camera::step (f32 dtime)
136
137
{
138
+ if (m_view_bobbing_fall > 0 )
139
+ {
140
+ m_view_bobbing_fall -= 3 * dtime;
141
+ if (m_view_bobbing_fall <= 0 )
142
+ m_view_bobbing_fall = -1 ; // Mark the effect as finished
143
+ }
144
+
137
145
if (m_view_bobbing_state != 0 )
138
146
{
139
147
// f32 offset = dtime * m_view_bobbing_speed * 0.035;
@@ -237,11 +245,28 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize,
237
245
m_playernode->setRotation (v3f (0 , -1 * player->getYaw (), 0 ));
238
246
m_playernode->updateAbsolutePosition ();
239
247
240
- // Get camera tilt timer (hurt animation)
248
+ // Get camera tilt timer (hurt animation)
241
249
float cameratilt = fabs (fabs (player->hurt_tilt_timer -0.75 )-0.75 );
242
250
251
+ // Fall bobbing animation
252
+ float fall_bobbing = 0 ;
253
+ if (player->camera_impact >= 1 )
254
+ {
255
+ if (m_view_bobbing_fall == -1 ) // Effect took place and has finished
256
+ player->camera_impact = m_view_bobbing_fall = 0 ;
257
+ else if (m_view_bobbing_fall == 0 ) // Initialize effect
258
+ m_view_bobbing_fall = 1 ;
259
+
260
+ // Convert 0 -> 1 to 0 -> 1 -> 0
261
+ fall_bobbing = m_view_bobbing_fall < 0.5 ? m_view_bobbing_fall * 2 : -(m_view_bobbing_fall - 0.5 ) * 2 + 1 ;
262
+ // Smoothen and invert the above
263
+ fall_bobbing = sin (fall_bobbing * 0.5 * M_PI) * -1 ;
264
+ // Amplify according to the intensity of the impact
265
+ fall_bobbing *= (1 - rangelim (50 / player->camera_impact , 0 , 1 )) * 5 ;
266
+ }
267
+
243
268
// Set head node transformation
244
- m_headnode->setPosition (player->getEyeOffset ()+v3f (0 ,cameratilt*-player->hurt_tilt_strength ,0 ));
269
+ m_headnode->setPosition (player->getEyeOffset ()+v3f (0 ,cameratilt*-player->hurt_tilt_strength +fall_bobbing ,0 ));
245
270
m_headnode->setRotation (v3f (player->getPitch (), 0 , cameratilt*player->hurt_tilt_strength ));
246
271
m_headnode->updateAbsolutePosition ();
247
272
0 commit comments