diff --git a/src/p_local.h b/src/p_local.h
index 96c71ed8ace16cd812aa8f34eda62993d26c8f88..5f47f8d05946c13262e5711f2f161e7c06d518b7 100644
--- a/src/p_local.h
+++ b/src/p_local.h
@@ -308,13 +308,13 @@ void P_PushableThinker(mobj_t *mobj);
 void P_SceneryThinker(mobj_t *mobj);
 
 fixed_t P_MobjFloorZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t y, fixed_t radius, line_t *line, boolean lowest, boolean perfect);
-fixed_t P_MobjCeilingZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t y, fixed_t radius, line_t *line, boolean highest, boolean perfect);
+fixed_t P_MobjCeilingZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t y, fixed_t radius, line_t *line, boolean lowest, boolean perfect);
 #define P_GetFloorZ(mobj, sector, x, y, line) P_MobjFloorZ(sector, NULL, x, y, mobj->radius, line, false, false)
-#define P_GetCeilingZ(mobj, sector, x, y, line) P_MobjCeilingZ(sector, NULL, x, y, mobj->radius, line, false, false)
-#define P_GetFOFTopZ(mobj, sector, fof, x, y, line) P_MobjCeilingZ(sectors + fof->secnum, sector, x, y, mobj->radius, line, true, false)
+#define P_GetCeilingZ(mobj, sector, x, y, line) P_MobjCeilingZ(sector, NULL, x, y, mobj->radius, line, true, false)
+#define P_GetFOFTopZ(mobj, sector, fof, x, y, line) P_MobjCeilingZ(sectors + fof->secnum, sector, x, y, mobj->radius, line, false, false)
 #define P_GetFOFBottomZ(mobj, sector, fof, x, y, line) P_MobjFloorZ(sectors + fof->secnum, sector, x, y, mobj->radius, line, true, false)
 #define P_GetSpecialBottomZ(mobj, src, bound) P_MobjFloorZ(src, bound, mobj->x, mobj->y, mobj->radius, NULL, src != bound, true)
-#define P_GetSpecialTopZ(mobj, src, bound) P_MobjCeilingZ(src, bound, mobj->x, mobj->y, mobj->radius, NULL, src != bound, true)
+#define P_GetSpecialTopZ(mobj, src, bound) P_MobjCeilingZ(src, bound, mobj->x, mobj->y, mobj->radius, NULL, src == bound, true)
 
 boolean P_InsideANonSolidFFloor(mobj_t *mobj, ffloor_t *rover);
 boolean P_CheckDeathPitCollide(mobj_t *mo);
diff --git a/src/p_mobj.c b/src/p_mobj.c
index 01a49c810d4f810dd91aa91f4d9028754cc356a6..592d87539c2a628e5f35a89f6b44200c83336a70 100644
--- a/src/p_mobj.c
+++ b/src/p_mobj.c
@@ -1168,7 +1168,7 @@ fixed_t P_MobjFloorZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t y,
 		return sector->floorheight;
 }
 
-fixed_t P_MobjCeilingZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t y, fixed_t radius, line_t *line, boolean highest, boolean perfect)
+fixed_t P_MobjCeilingZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t y, fixed_t radius, line_t *line, boolean lowest, boolean perfect)
 {
 	I_Assert(sector != NULL);
 
@@ -1187,7 +1187,7 @@ fixed_t P_MobjCeilingZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t
 		else
 			testy = -radius;
 
-		if ((slope->zdelta > 0) ^ !!(highest)) {
+		if ((slope->zdelta > 0) ^ !!(lowest)) {
 			testx = -testx;
 			testy = -testy;
 		}
@@ -1206,10 +1206,10 @@ fixed_t P_MobjCeilingZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t
 			fixed_t bbox[4];
 			fixed_t finalheight;
 
-			if (highest)
-				finalheight = INT32_MIN;
-			else
+			if (lowest)
 				finalheight = INT32_MAX;
+			else
+				finalheight = INT32_MIN;
 
 			bbox[BOXLEFT] = x-radius;
 			bbox[BOXRIGHT] = x+radius;
@@ -1225,10 +1225,10 @@ fixed_t P_MobjCeilingZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t
 				if (P_BoxOnLineSide(bbox, ld) != -1)
 					continue;
 
-				if (highest)
-					finalheight = max(finalheight, HighestOnLine(radius, x, y, ld, slope, false));
+				if (lowest)
+					finalheight = max(finalheight, HighestOnLine(radius, x, y, ld, slope, true));
 				else
-					finalheight = min(finalheight, HighestOnLine(radius, x, y, ld, slope, true));
+					finalheight = min(finalheight, HighestOnLine(radius, x, y, ld, slope, false));
 			}
 
 			return finalheight;
@@ -1239,7 +1239,7 @@ fixed_t P_MobjCeilingZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t
 		if (line == NULL)
 			return P_GetSlopeZAt(slope, x, y);
 
-		return HighestOnLine(radius, x, y, line, slope, highest);
+		return HighestOnLine(radius, x, y, line, slope, lowest);
 	} else // Well, that makes it easy. Just get the ceiling height
 		return sector->ceilingheight;
 }
@@ -2173,9 +2173,12 @@ boolean P_CheckDeathPitCollide(mobj_t *mo)
 	if (mo->player && mo->player->pflags & PF_GODMODE)
 		return false;
 
-	fixed_t sectorFloor = P_MobjFloorZ(mo->subsector->sector, NULL, mo->x, mo->y, mo->radius, NULL, true, false);
+	fixed_t sectorFloor = P_MobjFloorZ(mo->subsector->sector, NULL, mo->x, mo->y, mo->radius, NULL, false, false);
 	fixed_t sectorCeiling = P_MobjCeilingZ(mo->subsector->sector, NULL, mo->x, mo->y, mo->radius, NULL, true, false);
 
+	if (mo->player)
+		CONS_Printf("floorz is %d\nceilingz is %d\n", sectorFloor >> FRACBITS, sectorCeiling >> FRACBITS);
+
 	if (((mo->z <= sectorFloor
 		&& ((mo->subsector->sector->flags & MSF_TRIGGERSPECIAL_HEADBUMP) || !(mo->eflags & MFE_VERTICALFLIP)) && (mo->subsector->sector->flags & MSF_FLIPSPECIAL_FLOOR))
 		|| (mo->z + mo->height >= sectorCeiling