summaryrefslogtreecommitdiffstats
path: root/src/Mobs/AggressiveMonster.cpp
diff options
context:
space:
mode:
authorarchshift <admin@archshift.com>2014-04-25 21:59:55 +0200
committerarchshift <admin@archshift.com>2014-04-26 00:49:11 +0200
commit5ffdaa8142da27c68f467f26c4f28129865b7bf9 (patch)
tree99487f8452bca24965e2a0e17882d1e5733b74aa /src/Mobs/AggressiveMonster.cpp
parentMerge remote-tracking branch 'upstream/master' (diff)
downloadcuberite-5ffdaa8142da27c68f467f26c4f28129865b7bf9.tar
cuberite-5ffdaa8142da27c68f467f26c4f28129865b7bf9.tar.gz
cuberite-5ffdaa8142da27c68f467f26c4f28129865b7bf9.tar.bz2
cuberite-5ffdaa8142da27c68f467f26c4f28129865b7bf9.tar.lz
cuberite-5ffdaa8142da27c68f467f26c4f28129865b7bf9.tar.xz
cuberite-5ffdaa8142da27c68f467f26c4f28129865b7bf9.tar.zst
cuberite-5ffdaa8142da27c68f467f26c4f28129865b7bf9.zip
Diffstat (limited to 'src/Mobs/AggressiveMonster.cpp')
-rw-r--r--src/Mobs/AggressiveMonster.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index 0901f85a9..cafa7ee74 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,18 @@ void cAggressiveMonster::Attack(float a_Dt)
+bool cAggressiveMonster::IsMovingToTargetPosition()
+{
+ float epsilon = 0.000000000001;
+ //Difference between destination x and target x is negligable (to 10^-12 precision)
+ if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < epsilon)
+ {
+ return false;
+ }
+ //Difference between destination z and target z is negligable (to 10^-12 precision)
+ else if (fabsf(m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon)
+ {
+ return false;
+ }
+ return true;
+}