Stirille's Sprite Positioning (Raycasting). Some problems implementing it for mine


 private function proj3D(spr):Boolean {  
  
   var dx:Number = spr.ax-pX*8;
   var dy:Number = spr.ay-pY*8;
   var $d:Number= Math.sqrt(dx*dx + dy*dy); // dist to sprite
   spr.d = $d;
   if ($d < 0.3 ) return false;  // check if sprite is behind player 
   var vAngle:Number = charMC.rotation;
   var objW:Number = spr.objW; // just a reference to sprite's width
   var objAng:Number = radToDeg*Math.atan(Math.abs(dy/dx));
   // Angle fixes
   if (dx < 0 && dy > 0) {
    objAng = 180-objAng;
   } else if (dx < 0 && dy < 0) {
    objAng += 180;
   } else if (dx > 0 && dy < 0) {
    objAng = 360-objAng;
    if (vAngle < 90) {
     vAngle += 360;
    }
   } else if (vAngle > 270) {
    objAng += 360;
   }
   // Find scale ratio values
   var amount:Number = (vAngle + fov*0.5 - objAng)/fov;
   var h:Number = dist[Math.round(Math.max(Math.min(amount*camWidth, camWidth-1), 0))]/$d;
   // Find left and right boundaries for displayed sprite
   var lPt:Number = camWidth - camWidth*amount - objW*0.5*h;
   var rPt:Number = camWidth - camWidth*amount + objW*0.5*h;
   spr.sL=lPt;
   spr.sR=rPt;
   
   // check if within camera otherwise end it here;
   if ( rPt < 0 || lPt > camWidth )  return false;
   spr.sH = h*spr.objH;
   spr.sx = camWidth - camWidth*amount;
   spr.sy = h*0.5 + camHeight*0.5  - roll - spr.sH*0.5;
  (rPt,spr.sy)<$d!=0 ) return false;
   spr.sxc = h*spr.objW*fovAdjust;
   return true;
  }

I already did the necessary dist and fov precalculations for the camera earlier (where “camWidth” is also the amount of rays used) . I also clamped the player rotation to be from 0 degrees to 359 degrees. But somehow it just doesn’t work for the quadrant beyond 180 degrees. The thing is, when my character goes from 0 degrees (facing straight rightwards) to 180 degrees (facing straight leftwards), somehow once my character crosses the 180 degree mark into the top-left quadrant, all previously-seen sprites from the bottom-left quadrant behind the 180 degree mark mysteriously vanishes while all sprites above the 180 degree mark (in top-left quadrant) doesn’t appear either. It’s like for some strange reason, the top-left and bottom-left quadrant are 2 seperate sectors or something…And no sprites are shown in the top-left quadrant at all. However, if looking into the top-left quadrant, i can still see sprites from the top-right quadrant ( 270 degrees onwards).

Whether i use atan (with the angle fix calculations) or atan2…it doesn’t make a difference. Can someone Pleeease help???