diff --git a/source/src/client.cpp b/source/src/client.cpp index 9665705a..8948614e 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -294,7 +294,7 @@ void c2sinfo(playerent *d) // send update to the server putint(q, d->clientnum); putuint(q, (int)(d->o.x*DMF)); // quantize coordinates to 1/16th of a cube, between 1 and 3 bytes putuint(q, (int)(d->o.y*DMF)); - putuint(q, (int)(d->o.z*DMF)); + putuint(q, (int)((d->o.z - d->eyeheight)*DMF)); putuint(q, (int)d->yaw); putint(q, (int)d->pitch); putint(q, (int)d->roll); diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index b4bbe102..25ee706f 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -233,12 +233,14 @@ VARP(smoothdist, 0, 8, 16); void predictplayer(playerent *d, bool move) { d->o = d->newpos; + d->o.z += d->eyeheight; d->yaw = d->newyaw; d->pitch = d->newpitch; if(move) { moveplayer(d, 1, false); d->newpos = d->o; + d->newpos.z -= d->eyeheight; } float k = 1.0f - float(lastmillis - d->smoothmillis)/smoothmove; if(k>0) diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index f5b68f17..7343cc82 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -85,6 +85,7 @@ void parsepositions(ucharbuf &p) vec oldpos(d->o); float oldyaw = d->yaw, oldpitch = d->pitch; d->o = o; + d->o.z += d->eyeheight; d->yaw = yaw; d->pitch = pitch; d->roll = roll; @@ -109,11 +110,13 @@ void parsepositions(ucharbuf &p) else if(smoothmove && d->smoothmillis>=0 && oldpos.dist(d->o) < smoothdist) { d->newpos = d->o; + d->newpos.z -= d->eyeheight; d->newyaw = d->yaw; d->newpitch = d->pitch; d->o = oldpos; d->yaw = oldyaw; d->pitch = oldpitch; + oldpos.z -= d->eyeheight; (d->deltapos = oldpos).sub(d->newpos); d->deltayaw = oldyaw - d->newyaw; if(d->deltayaw > 180) d->deltayaw -= 360; diff --git a/source/src/physics.cpp b/source/src/physics.cpp index f179634f..ba81026b 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -263,29 +263,30 @@ void resizephysent(physent *pl, int moveres, int curtime, float min, float max) { if(pl->eyeheightvel==0.0f) return; - float drop = 0.0f, rise = 0.0f; const bool water = hdr.waterlevel>pl->o.z; const float speed = curtime*pl->maxspeed/(water ? 2000.0f : 1000.0f); - float h = pl->eyeheightvel; - h *= speed; + float h = pl->eyeheightvel * speed / moveres; loopi(moveres) { - const float f = 1.0f/moveres; - pl->eyeheight += f*h; - if(!collide(pl, false, drop, rise)) + pl->eyeheight += h; + pl->o.z += h; + if(!collide(pl)) { - pl->eyeheight -= f*h; // collided, revert mini-step + pl->eyeheight -= h; // collided, revert mini-step + pl->o.z -= h; break; } if(pl->eyeheighto.z += min - pl->eyeheight; pl->eyeheight = min; pl->eyeheightvel = 0.0f; break; } if(pl->eyeheight>max) { + pl->o.z -= pl->eyeheight - max; pl->eyeheight = max; pl->eyeheightvel = 0.0f; break; @@ -601,6 +602,7 @@ VAR(physinterp, 0, 1, 1); void interppos(physent *pl) { pl->o = pl->newpos; + pl->o.z += pl->eyeheight; int diff = lastphysframe - (lastmillis + curtime); if(diff <= 0 || !physinterp) return; @@ -618,7 +620,11 @@ void moveplayer(physent *pl, int moveres, bool local) return; } - if(local) pl->o = pl->newpos; + if(local) + { + pl->o = pl->newpos; + pl->o.z += pl->eyeheight; + } loopi(physsteps-1) moveplayer(pl, moveres, local, physframetime); if(local) pl->deltapos = pl->o; moveplayer(pl, moveres, local, physframetime); @@ -626,6 +632,7 @@ void moveplayer(physent *pl, int moveres, bool local) { pl->newpos = pl->o; pl->deltapos.sub(pl->newpos); + pl->newpos.z -= pl->eyeheight; interppos(pl); } } @@ -669,7 +676,7 @@ void jumpn(bool on) void updatecrouch(playerent *p, bool on) { if(p->crouching == on) return; - const float crouchspeed = 5.625f; + const float crouchspeed = 0.6f; p->crouching = on; p->eyeheightvel = on ? -crouchspeed : crouchspeed; } @@ -722,7 +729,7 @@ void entinmap(physent *d) // brute force but effective way to find a free spa float dy = (rnd(21)-10)/10.0f*i; d->o.x += dx; d->o.y += dy; - if(collide(d, true, 0, 0)) + if(collide(d, true)) { d->resetinterp(); return; diff --git a/source/src/protos.h b/source/src/protos.h index fe957777..a94bb871 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -532,7 +532,6 @@ extern bool raycubelos(const vec &from, const vec &to, float margin = 0); extern void moveplayer(physent *pl, int moveres, bool local); extern void moveplayer(physent *pl, int moveres, bool local, int curtime); extern void movebounceent(bounceent *p, int moveres, bool local); -extern bool collide(physent *d, bool spawn, float drop, float rise); extern void entinmap(physent *d); extern void physicsframe(); extern void mousemove(int dx, int dy); @@ -540,7 +539,7 @@ extern void fixcamerarange(physent *cam = camera1); extern float floor(short x, short y); extern void updatecrouch(playerent *p, bool on); extern bool objcollide(physent *d, vec &objpos, float objrad, float objheight); -extern bool collide(physent *d, bool spawn, float drop, float rise); +extern bool collide(physent *d, bool spawn = false, float drop = 0, float rise = 0); // sound extern void playsound(int n, int priority = SP_NORMAL);