From 0690788cdfefbec3c74057e0b60d9f5aae935303 Mon Sep 17 00:00:00 2001 From: worktycho Date: Wed, 4 Jun 2014 14:16:24 +0100 Subject: Replaced strange algebra with dot product. 10 degrees is a completely arbitary constant I pulled from nowhere. Feel free to adjust this value. --- src/Mobs/Enderman.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index 416b541ed..d26639a75 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -42,12 +42,14 @@ public: return false; } - Direction.Normalize(); Vector3d LookVector = a_Player->GetLookVector(); - LookVector.Normalize(); + double dot = Direction.Dot(LookVector); - if ((Direction - LookVector).SqrLength() > 0.02) + // 0.09 rad ~ 5 degrees. + // If the players crosshars are 10 degrees from the line linking the endermen + // It counts as looking. + if (dot > cos(0.09)) { return false; } @@ -140,4 +142,4 @@ void cEnderman::EventLosePlayer() super::EventLosePlayer(); m_bIsScreaming = false; GetWorld()->BroadcastEntityMetadata(*this); -} \ No newline at end of file +} -- cgit v1.2.3