summaryrefslogtreecommitdiffstats
path: root/src/Mobs/AggressiveMonster.cpp
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-05-07 12:54:58 +0200
committerHowaner <franzi.moos@googlemail.com>2014-05-07 12:54:58 +0200
commitf5fe3682201e2f1356e3a5c408eb8296b542e072 (patch)
tree208ec7a760b9e909fbb43e1a12ee43d866cb9df7 /src/Mobs/AggressiveMonster.cpp
parentRemove old import (diff)
parentFixed wires powering wires diagonally below them (diff)
downloadcuberite-f5fe3682201e2f1356e3a5c408eb8296b542e072.tar
cuberite-f5fe3682201e2f1356e3a5c408eb8296b542e072.tar.gz
cuberite-f5fe3682201e2f1356e3a5c408eb8296b542e072.tar.bz2
cuberite-f5fe3682201e2f1356e3a5c408eb8296b542e072.tar.lz
cuberite-f5fe3682201e2f1356e3a5c408eb8296b542e072.tar.xz
cuberite-f5fe3682201e2f1356e3a5c408eb8296b542e072.tar.zst
cuberite-f5fe3682201e2f1356e3a5c408eb8296b542e072.zip
Diffstat (limited to 'src/Mobs/AggressiveMonster.cpp')
-rw-r--r--src/Mobs/AggressiveMonster.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index 0901f85a9..85b122034 100644
--- a/src/Mobs/AggressiveMonster.cpp
+++ b/src/Mobs/AggressiveMonster.cpp
@@ -37,7 +37,7 @@ void cAggressiveMonster::InStateChasing(float a_Dt)
}
}
- if (((float)m_FinalDestination.x != (float)m_Target->GetPosX()) || ((float)m_FinalDestination.z != (float)m_Target->GetPosZ()))
+ if (!IsMovingToTargetPosition())
{
MoveToPosition(m_Target->GetPosition());
}
@@ -106,3 +106,17 @@ void cAggressiveMonster::Attack(float a_Dt)
+bool cAggressiveMonster::IsMovingToTargetPosition()
+{
+ // Difference between destination x and target x is negligible (to 10^-12 precision)
+ if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < std::numeric_limits<float>::epsilon())
+ {
+ return false;
+ }
+ // Difference between destination z and target z is negligible (to 10^-12 precision)
+ else if (fabsf((float)m_FinalDestination.z - (float)m_Target->GetPosZ()) > std::numeric_limits<float>::epsilon())
+ {
+ return false;
+ }
+ return true;
+}