From 50764a86cfb6ae27cc453eebe5c0d56d80eeb4a2 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Mon, 22 Aug 2016 16:24:34 +0200 Subject: [PATCH] fix rotated clip entity collision checks * properly rotate the player hitbox * add "corner bounce" (doesn't work flawlessly - but it's probably as good as possible with this kind of physics engine) --- source/src/physics.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 360c0f8d..11cd3391 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -99,8 +99,8 @@ int cornertest(int x, int y, int &bx, int &by, int &bs, sqr *&s, sqr *&h) // x >>= mip; y >>= mip; int mfactor = sfactor - mip; - bx = x<eyeheight; @@ -148,7 +150,13 @@ bool mmcollide(physent *d, float &hi, float &lo) // collide with a map case 3: // clip rotated 45° { float rx = (e.x - d->o.x) * 0.707106781f, ry = (e.y - d->o.y) * 0.707106781f, rr = d->radius * 1.414213562f; // rotate player instead of clip (adjust player radius to compensate) - hitarea = fabs(rx - ry) < float(e.attr3) / ENTSCALE5 + rr && fabs(rx + ry) < float(e.attr2) / ENTSCALE5 + rr; + float a1 = fabs(rx - ry) - float(e.attr3) / ENTSCALE5 - rr, a2 = fabs(rx + ry) - float(e.attr2) / ENTSCALE5 - rr; + if(a1 < 0 && a2 < 0) + { + float a3 = a1 + a2 + rr; + if(a3 < 0) hitarea = true; + if(a3 < -1e-2 && (a3 < -rr || a1 * a2 < 0.42f)) cornersurface = a1 > a2 ? 1 : 2; + } break; } } @@ -164,6 +172,7 @@ bool mmcollide(physent *d, float &hi, float &lo) // collide with a map if(dz < cz - 0.42) { if(czlo) lo = cz+ch; if(hi-lo < playerheight) return true; + if(dz + (d->type != ENT_BOUNCE ? 1.26 : 0) > cz + ch || dz + playerheight < cz) cornersurface = 0; } } else if(e.type==MAPMODEL) @@ -200,7 +209,6 @@ bool objcollide(physent *d, const vec &objpos, float objrad, float objheight) // // all collision happens here // spawn is a dirty side effect used in spawning // drop & rise are supplied by the physics below to indicate gravity/push for current mini-timestep -static int cornersurface = 0; bool collide(physent *d, bool spawn, float drop, float rise) {