]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/View.qc
Merge branch 'master' into mirceakitsune/event_chasecam
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / View.qc
index 09ec96eabaaa9ece2608496c64c551d646d1b695..540c077873613447ef72ee23c13694cd32c84c25 100644 (file)
@@ -366,6 +366,8 @@ vector myhealth_gentlergb;
 float contentavgalpha, liquidalpha_prev;
 vector liquidcolor_prev;
 
+float chase_current_distance;
+
 void CSQC_UpdateView(float w, float h)
 {
        entity e;
@@ -401,6 +403,39 @@ void CSQC_UpdateView(float w, float h)
        input_angles = warpzone_fixview_cl_viewangles;
        view_angles = warpzone_fixview_angles;
 
+       // event chase cam
+       if(spectatee_status >= 0 && (autocvar_cl_chase_death || autocvar_cl_chase_intermission))
+       if(autocvar_chase_active <= 0) // greater than 0 means it's enabled manually
+       {
+               if((autocvar_cl_chase_death && getstati(STAT_HEALTH) <= 0 && !intermission) || (autocvar_cl_chase_intermission && intermission) && intermission <= 1) // not during the map voting screen
+               {
+                       if(!autocvar_chase_active)
+                               cvar_set("chase_active", "-1"); // -1 enables chase_active as well as marking it as set by this code, and not by the user (which would be 1)
+
+                       // make the camera smooth back
+                       if(autocvar_cl_chase_speed && chase_current_distance < autocvar_cl_chase_distance)
+                               chase_current_distance += autocvar_cl_chase_speed * (autocvar_cl_chase_distance - chase_current_distance) * frametime; // slow down smoothly
+                       else if(chase_current_distance != autocvar_cl_chase_distance)
+                               chase_current_distance = autocvar_cl_chase_distance;
+
+                       vector target_origin;
+                       target_origin = pmove_org - view_forward * chase_current_distance;
+
+                       // don't allow the camera to go through walls
+                       traceline(pmove_org, target_origin, MOVE_NORMAL, self);
+                       if(trace_fraction == 1)
+                       {
+                               makevectors(view_angles);
+                               R_SetView(VF_ORIGIN, target_origin);
+                       }
+               }
+               else if(autocvar_chase_active < 0)
+               {
+                       cvar_set("chase_active", "0");
+                       chase_current_distance = 0; // start from 0
+               }
+       }
+
        if(autocvar_cl_lockview || (autocvar__hud_configure && spectatee_status <= 0))
        {
                pmove_org = freeze_pmove_org;