###

» Thu Oct 01, 2015 4:15 am

Pathfinding only needs a start location and a destination to work... so yes this should be possible.

What you need to do is pick a destination which is directly away from the danger and a distance proportional to how much danger the deer is feeling.

So if your deer is at dx,dy and your wolf is at wx,wy then you want to pick a destination zx,zy as:

closeness = distance(dx, dy, wx, wy)

if closeness <= maximumVisionOfDeer

howFarToRun = maximumFarToRun / closeness

dangerAngle = angle(dx, dy, wx, wy)

safeAngle = dangerAngle + 180

zx = dx + cos(safeAngle) * howFarToRun

zy = dy + sin(safeAngle) * howFarToRun

endif

Then you can pathfind from dx,dy to zx,zy.

Note: maximumFarToRun is the maximum distance the deer will run if the wolf is right next to it (closeness = 1), if your wolf can get even closer than 1 (e.g. 0.1) then this won't work the same and you might want to limit the values into the equation.

Note: if zx,zy is inside a tree, you either need a pathfinding algorithm that will go as close as it can (and not just fail), or you should jiggle the destination a bit with a random offset until it is not in a tree.

There are tons of other things you could add, but this will work to get you started I think.