Tilt camera on player damage (tweaked by PilzAdam)
authorJeija <norrepli@gmail.com>
Sat, 28 Apr 2012 00:06:25 +0000 (02:06 +0200)
committerPilzAdam <PilzAdam@gmx.de>
Thu, 3 Jan 2013 14:16:46 +0000 (15:16 +0100)
src/camera.cpp
src/game.cpp
src/player.h

index 1b9a8c763e6518e176daeeec787b076f28476c76..33e85d06926e9568c4e02de64723e01cf23ba517 100644 (file)
@@ -233,9 +233,12 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize,
        m_playernode->setRotation(v3f(0, -1 * player->getYaw(), 0));
        m_playernode->updateAbsolutePosition();
 
+       //Get camera tilt timer (hurt animation)
+       float cameratilt = fabs(fabs(player->hurt_tilt_timer-0.75)-0.75);
+
        // Set head node transformation
-       m_headnode->setPosition(player->getEyeOffset());
-       m_headnode->setRotation(v3f(player->getPitch(), 0, 0));
+       m_headnode->setPosition(player->getEyeOffset()+v3f(0,cameratilt*-player->hurt_tilt_strength,0));
+       m_headnode->setRotation(v3f(player->getPitch(), 0, cameratilt*player->hurt_tilt_strength));
        m_headnode->updateAbsolutePosition();
 
        // Compute relative camera position and target
index 05f1da5e0b83782c149607c400adbb294fc0a83e..5a278a52e74f8a21d94e5e514015fadf9788bd79 100644 (file)
@@ -1356,6 +1356,10 @@ void the_game(
        // NOTE: So we have to use getTime() and call run()s between them
        u32 lasttime = device->getTimer()->getTime();
 
+       LocalPlayer* player = client.getEnv().getLocalPlayer();
+       player->hurt_tilt_timer = 0;
+       player->hurt_tilt_strength = 0;
+
        for(;;)
        {
                if(device->run() == false || kill == true)
@@ -2055,8 +2059,13 @@ void the_game(
                                {
                                        //u16 damage = event.player_damage.amount;
                                        //infostream<<"Player damage: "<<damage<<std::endl;
+
                                        damage_flash += 100.0;
                                        damage_flash += 8.0 * event.player_damage.amount;
+
+                                       player->hurt_tilt_timer = 1.5;
+                                       player->hurt_tilt_strength = event.player_damage.amount/2;
+                                       player->hurt_tilt_strength = rangelim(player->hurt_tilt_strength, 2.0, 10.0);
                                }
                                else if(event.type == CE_PLAYER_FORCE_MOVE)
                                {
@@ -2088,6 +2097,10 @@ void the_game(
 
                                        damage_flash = 0;
 
+                                       LocalPlayer* player = client.getEnv().getLocalPlayer();
+                                       player->hurt_tilt_timer = 0;
+                                       player->hurt_tilt_strength = 0;
+
                                        /*LocalPlayer* player = client.getLocalPlayer();
                                        player->setPosition(player->getPosition() + v3f(0,-BS,0));
                                        camera.update(player, busytime, screensize);*/
@@ -3057,6 +3070,16 @@ void the_game(
                        damage_flash -= 100.0*dtime;
                }
 
+               /*
+                       Damage camera tilt
+               */
+               if(player->hurt_tilt_timer > 0.0)
+               {
+                       player->hurt_tilt_timer -= dtime*5;
+                       if(player->hurt_tilt_timer < 0)
+                               player->hurt_tilt_strength = 0;
+               }
+
                /*
                        Draw gui
                */
index 5a489e64f813cd2b3febf5d688f92ef0b0e23944..67b02c3445d15b7cac634ce8b6917063f3bfce78 100644 (file)
@@ -209,6 +209,9 @@ public:
 
        u16 hp;
 
+       float hurt_tilt_timer;
+       float hurt_tilt_strength;
+
        u16 peer_id;
        
        std::string inventory_formspec;