Welcome to the Bitcave! Nerdiness, Jokes, Mods, Ideas, and coding!

hmmm… there is one big problem in this implementation, the path that LOS_ONE() chacks is incorrect.
for example, if the fild is set like this (yellow = position, gray = obstacle and red = target):

this script will move up twice, both in x and y, and then it will move twice to the right just on the x, causing a path that looks like this:

as you can see, the obstacle isn’t counts as “blocking the way”, but if you think about it it should! (imagine yourself standing in the yellow block, trying to look at the target), the correct path should look close to something like this:

as you can see its represents more correctly a straight line, and in this way the obstacle counts as “blocking the way”.
one way that i know of to achieve good representation of a straight line in a case like this is to use the Bresenham’s line algorithm.

if you are rally intrested in AI for games i would recommend a book called “AI for Game Developers” by David M. Bourg and Glenn Seeman (this is how i know this stuff), its a really good book, but I wouldn’t buy it just to mod stonehearth.

2 Likes