From 0e6476806a2deb454c28e96ecc954f9fa4ba48f8 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sun, 27 Sep 2015 00:28:34 +0200 Subject: [PATCH] fix crouching, jumping and doublejumping * fix the old check for different jump start heights as requirement for doublejumps * better handle multiple binds for the "jump" command * delay relaxed floorclamping for crouching * remove some redundant code --- source/src/entity.h | 2 +- source/src/physics.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/src/entity.h b/source/src/entity.h index 888b4274..2f3a79ce 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -140,7 +140,7 @@ public: int last_pos; physent() : o(0, 0, 0), deltapos(0, 0, 0), newpos(0, 0, 0), yaw(270), pitch(0), roll(0), pitchvel(0), - crouching(false), crouchedinair(false), trycrouch(false), cancollide(true), stuck(false), scoping(false), shoot(false), lastjump(0), lastjumpheight(0), lastsplash(0), state(CS_ALIVE), last_pos(0) + crouching(false), crouchedinair(false), trycrouch(false), cancollide(true), stuck(false), scoping(false), shoot(false), lastjump(0), lastjumpheight(200), lastsplash(0), state(CS_ALIVE), last_pos(0) { reset(); } diff --git a/source/src/physics.cpp b/source/src/physics.cpp index d72d16f3..6b76515e 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -333,7 +333,7 @@ bool collide(physent *d, bool spawn, float drop, float rise) d->vel.z = 0; // cancel out jumping velocity } - const float floorclamp = d->crouching ? 0.1f : 0.01f; + const float floorclamp = d->crouching && (!d->lastjump || lastmillis - d->lastjump > 250) ? 0.1f : 0.01f; d->onfloor = d->o.z-eyeheight-lo < floorclamp; } return false; @@ -478,8 +478,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) pl->o.add(d); if(pl->jumpnext && !pl->trycrouch) { - pl->jumpnext = true; // fly directly upwards while holding jump keybinds - pl->vel.z = 0.5f; + pl->vel.z = 0.5f; // fly directly upwards while holding jump keybinds } else if (pl->trycrouch && !pl->jumpnext) { @@ -518,7 +517,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) if(pl->jumpnext) { pl->jumpnext = false; - bool doublejump = pl->lastjump && lastmillis-pl->lastjump < 250 && pl->strafe != 0 && pl->lastjumpheight != 0 && pl->lastjumpheight != pl->o.z; + bool doublejump = pl->lastjump && lastmillis - pl->lastjump < 250 && pl->strafe != 0 && pl->o.z - pl->lastjumpheight > 0.2f; pl->lastjumpheight = pl->o.z; pl->vel.z = 2.0f; // physics impulse upwards if(doublejump && curfullspeed > 0.1f) // more velocity on double jump @@ -828,12 +827,13 @@ void attack(bool on) void jumpn(bool on) { + static bool wason = false; + player1->jumpnext = on && !wason && !player1->crouching && !intermission && !player1->isspectating(); + wason = on; if(player1->isspectating()) { if(lastmillis - player1->respawnoffset > 1000 && on) togglespect(); } - else if(player1->crouching || intermission) return; - else player1->jumpnext = on; } void updatecrouch(playerent *p, bool on)