From: RĂ©mi Verschelde Date: Sat, 28 Jan 2017 14:26:00 +0000 (+0100) Subject: AI: Prevent division by 0 when enemy has no velocity X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=a15391fb6e514e033a50c714ef32968d21419f19;p=lugaru.git AI: Prevent division by 0 when enemy has no velocity Fixes #45. --- 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); }