From 8284aaf7b34b7ac688d0d22add316c2f51110d5d Mon Sep 17 00:00:00 2001 From: driAn Date: Sat, 27 Sep 2008 16:20:32 +0000 Subject: [PATCH] avoid getting stuck when un-crouching git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2778 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/entity.h | 5 +++-- source/src/physics.cpp | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/src/entity.h b/source/src/entity.h index 6ae9a619..a7c04164 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -104,6 +104,7 @@ struct physent char move, strafe; uchar state, type; static const int crouchtime; + float lastspacehi; physent() : o(0, 0, 0), deltapos(0, 0, 0), newpos(0, 0, 0), yaw(270), pitch(0), roll(0), pitchvel(0), crouching(false), trycrouch(false), cancollide(true), stuck(false), lastcrouch(0), lastsplash(0), state(CS_ALIVE) @@ -120,13 +121,13 @@ struct physent void reset() { - vel.x = vel.y = vel.z = 0; + vel.x = vel.y = vel.z = lastspacehi = 0.0f; move = strafe = 0; timeinair = lastcrouch = lastsplash = 0; onfloor = onladder = inwater = jumpnext = crouching = trycrouch = stuck = false; } - virtual float dyneyeheight() + virtual float dyneyeheight() const { extern int lastmillis; const float croucheyeheight = eyeheight*3.0f/4.0f; diff --git a/source/src/physics.cpp b/source/src/physics.cpp index a7b47892..ca9842e3 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -241,6 +241,7 @@ bool collide(physent *d, bool spawn, float drop, float rise) } d->onfloor = d->o.z-eyeheight-lo < (lastmillis-d->lastcrouch<=physent::crouchtime ? 0.1f : 0.01f); + d->lastspacehi = spacehi; } return true; } @@ -605,6 +606,7 @@ void jumpn(bool on) void updatecrouch(playerent *p, bool on) { if(p->crouching == on) return; + if(p==player1 && p->lastspacehi<1.0f && !on) return; p->crouching = on; const int progress = lastmillis-p->lastcrouch; if(progress > physent::crouchtime) p->lastcrouch = lastmillis; // new crouch