]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
natural crouch: initial commit TimePath/natural_crouch
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 13 Mar 2016 04:16:24 +0000 (15:16 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Mon, 13 Jun 2016 07:25:57 +0000 (17:25 +1000)
qcsrc/common/constants.qh
qcsrc/server/cl_client.qc

index 28db23dc11a13fd08b5365a30ca670e2b8638701..088d8f4fe11bf7083378da324b8b587e7bd369cc 100644 (file)
@@ -210,6 +210,8 @@ const int SERVERFLAG_PLAYERSTATS = 4;
 vector autocvar_sv_player_maxs = '16 16 45';
 vector autocvar_sv_player_mins = '-16 -16 -24';
 vector autocvar_sv_player_viewoffset = '0 0 20';
+/** pull legs up in the air */
+bool autocvar_sv_player_crouch_natural = false;
 vector autocvar_sv_player_crouch_maxs = '16 16 25';
 vector autocvar_sv_player_crouch_mins = '-16 -16 -24';
 vector autocvar_sv_player_crouch_viewoffset = '0 0 20';
index 28d9c6c1a04895bc264ace6bbcd99182e44f6f89..7d7383a0c8025727c9c1cc142f210d9726f6a616 100644 (file)
@@ -216,7 +216,7 @@ void PutObserverInServer(entity this)
                // needed for player sounds
                this.model = "";
                FixPlayermodel(this);
-        } 
+        }
         setmodel(this, MDL_Null);
         setsize(this, STAT(PL_CROUCH_MIN, NULL), STAT(PL_CROUCH_MAX, NULL));
         this.view_ofs = '0 0 0';
@@ -2279,20 +2279,46 @@ void PlayerPreThink ()
                        do_crouch = false;
         }
 
-               if (do_crouch) {
-                       if (!this.crouch) {
+               if (do_crouch)
+               {
+                       if (!this.crouch)
+                       {
                                this.crouch = true;
-                               this.view_ofs = STAT(PL_CROUCH_VIEW_OFS, this);
-                               setsize(this, STAT(PL_CROUCH_MIN, this), STAT(PL_CROUCH_MAX, this));
+                               vector mn = STAT(PL_CROUCH_MIN, this);
+                               vector mx = STAT(PL_CROUCH_MAX, this);
+                               if (autocvar_sv_player_crouch_natural && !IS_ONGROUND(this)) {
+                                       // pull feet up
+                                       float h = STAT(PL_MAX, this).z - STAT(PL_CROUCH_MAX, this).z;
+                                       mn.z += h;
+                                       mx.z += h;
+                                       this.view_ofs = STAT(PL_VIEW_OFS, this);
+                               } else {
+                                       this.view_ofs = STAT(PL_CROUCH_VIEW_OFS, this);
+                               }
+                               setsize(this, mn, mx);
                                // setanim(this, this.anim_duck, false, true, true); // this anim is BROKEN anyway
                        }
-               } else if (this.crouch) {
-            tracebox(this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), this.origin, false, this);
-            if (!trace_startsolid) {
-                this.crouch = false;
-                this.view_ofs = STAT(PL_VIEW_OFS, this);
-                setsize(this, STAT(PL_MIN, this), STAT(PL_MAX, this));
-            }
+               }
+               else
+               {
+                       if (this.crouch)
+                       {
+                           vector mn = STAT(PL_MIN, this);
+                vector mx = STAT(PL_MAX, this);
+                if (autocvar_sv_player_crouch_natural && IS_ONGROUND(this)) {
+                    // let feet down
+                    float h = STAT(PL_MAX, this).z - STAT(PL_CROUCH_MAX, this).z;
+                    mn.z += h;
+                    mx.z += h;
+                }
+                               tracebox(this.origin, mn, mx, this.origin, false, this);
+                               if (!trace_startsolid)
+                               {
+                                       this.crouch = false;
+                                       this.view_ofs = STAT(PL_VIEW_OFS, this);
+                                       setsize(this, STAT(PL_MIN, this), STAT(PL_MAX, this));
+                               }
+                       }
                }
 
                FixPlayermodel(this);