Talk:Enemy AI That Follows The Character Done Right/@comment-15974427-20150619031529/@comment-15974427-20150620024050

Thanks!

It did overflow most of the time, but I easily fixed it this way: deltaX=characterX/16-enemX/16 deltaY=characterY/16-enemY/16 enemDistance=SQR(deltaX*deltaX+deltaY*deltaY)*16 IF enemDistance<=enemSpeed THEN enemVelX=deltaX:enemVelY=deltaY:GOTO @enemMoveDone enemVelX=deltaX*enemSpeed/enemDistance enemVelY=deltaY*enemSpeed/enemDistance @enemMoveDone enemX=enemX+enemVelX enemY=enemY+enemVelY I simply divided characterX, characterY, enemX and enemY by 16 and then multiplied the SQR by 16 so it gives the original requested amount while not getting an Overflow error.

This really works: the enemy reaches the exact location of the player's X and Y values (except when coming from the right or from the down which leaves a .004 everytime (that's weird), but it's not a big problem!)