Conclusion
You
should now be able to run the application! Admittedly the name Fart
Sniffer is meant to be somewhat amusing. But the technique used could
be applied to other kinds of AI path finding/fallowing such as a game
where a scent trail is left behind by the player and a pack of wolves
or demons use it to track down the players location.
As you can
see from running the app the flies are not perfect, they sometimes
travel backwards away from a stronger scent to a weaker scent, but with
some minor tweaks you could direct the flies to always fallow a more
stronger scent. One thing that could be done is to use the alternative
way of setting the flies direction provided in the code in part 9.
- ' Try using this line instead
- 'F.Direction += ((R.Direction * 0.9F) + (Rnd() * (R.Direction * 0.2F)))
What
this code will do is instead of simply adding the direction of the
receptor to the fly's direction it takes 90 percent of the receptors
direction and adds a random of 0 to 20 percent of the receptors
direction. For example if the fly was facing 0 degrees and the
receptors direction is 45 degrees then the new fly direction would be
set to anywhere from 40 degrees to 50 degrees or so. This would add a
little more detail to the fly's behavior instead of always making hard
45 degree turns all the time.
I hope you have found this tutorial to be useful. The full source code can be downloaded from the Created by X website here
FartSniffer.zip If you are unable to download the file contact Created by: X using the contact info provided on the
http://www.createdbyx.com/ website and ask for a copy of the file.