From f36a106f2e1d3235c4e308e0f9b4ea389ae1093d Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Wed, 30 Jul 2008 21:40:18 +0000 Subject: [PATCH] spectator div-by-0 position bug git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2262 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/physics.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 2564902d..345e1631 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -398,18 +398,20 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) hitplayer = NULL; if(collide(pl, false, drop, rise)) continue; else collided = true; - // fs: trying to fix the spectator bug (monochrome screen et al) - //if(pl->type==ENT_CAMERA) continue; //return; + if(pl->type==ENT_CAMERA) return; if(pl->type==ENT_PLAYER && hitplayer) { float dx = hitplayer->o.x-pl->o.x, dy = hitplayer->o.y-pl->o.y, mag = sqrtf(dx*dx+dy*dy); - dx /= mag; - dy /= mag; - pl->o.x -= f*(dx + d.x); - pl->o.y -= f*(dy + d.y); - if(collide(pl, false, drop, rise)) continue; - pl->o.x += f*(dx + d.x); - pl->o.y += f*(dy + d.y); + if(mag) + { + dx /= mag; + dy /= mag; + pl->o.x -= f*(dx + d.x); + pl->o.y -= f*(dy + d.y); + if(collide(pl, false, drop, rise)) continue; + pl->o.x += f*(dx + d.x); + pl->o.y += f*(dy + d.y); + } } // player stuck, try slide along y axis pl->o.x -= f*d.x;