From a15391fb6e514e033a50c714ef32968d21419f19 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Verschelde?= Date: Sat, 28 Jan 2017 15:26:00 +0100 Subject: [PATCH] AI: Prevent division by 0 when enemy has no velocity Fixes #45. --- Source/Objects/Person.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Objects/Person.cpp b/Source/Objects/Person.cpp index 7f279de..1ac664c 100644 --- a/Source/Objects/Person.cpp +++ b/Source/Objects/Person.cpp @@ -8451,8 +8451,8 @@ void Person::doAI() //chase player XYZ rotatetarget = Person::players[0]->coords + Person::players[0]->velocity; XYZ targetpoint = Person::players[0]->coords; - if (distsq(&Person::players[0]->coords, &coords) < - distsq(&rotatetarget, &coords)) { + if (findLength(&velocity) != 0 && + distsq(&Person::players[0]->coords, &coords) < distsq(&rotatetarget, &coords)) { targetpoint += Person::players[0]->velocity * findDistance(&Person::players[0]->coords, &coords) / findLength(&velocity); } -- 2.39.5