Wednesday, May 26, 2004

[Ant Attack] The trouble with smells... seems is that there are far to many of them and it's really making the program chug.

The problem stems from the number of smells that are being dropped. Each ant has to do a Line of Sight (LOS) test against each smell, to figure out which is the strongest. The LOS is being done by Ray-Tracing from the source ant to the target smell and this takes some work.

Things I've tried to speed it up...

Increase the interval between dropping smells and increase the rate at which the smells decay. I reduced the dropped smells by the player to about 1/4 of the original amount. This doesn't seem to have effected the ants ability to track the player, so that good.

Done the same to the ants, so they drop smells less often too.

I've added a Field of Vision (FOV) check and a distance check between each ant and smell before doing the more complex LOS check. So if the smell is behind the ant or too far away, I don't even bother with the LOS. Even then I check the LOS to the player first, so if I can spot them I don't bother with any of the other smells.

Finallyy, I don't check the smells every game cycle but once a second. So each second the ants will re-check their targets.


Well I thought that had done the trick. I had about 8 ants all running round tracking me down once they'd gotten a wiff of me.

But then I tried it on a slightly lower spec machine and it was painful. Every second there'd be a small lag as the LOS checks went through.

The other problem is that as soon they find a smell they start dropping their own smells, other ants spot those and drop smells too! Soon you end up with too many smells. Speeding up the decay rate helped a little, but then reduced the usefulness of the smells, I may as well just resort to LOS to the player.

Things to Try Now

1. Tune the settings some more. Make the smells get dropped once every 2 seconds and last maybe 8 seconds, so each player and ant will only have at 4 smells on the go at once. You can cover quite a distance in 8 seconds so it should still help tracking once the player has moved out of sight. But the distance you can move in 2 seconds is so great that the player can run through relatively open areas with leaving at least one smell. Although I wouldn't want to push it up any more.

2. Make sure the order that the smells are checked in is strongest first. So as soon as there's LOS to a smell the rest of the checks can be aborted. This should be easy as everytime a new smell is created I can push it onto the top of the smell stack.

3. The trouble is when an ant can't see any smells, they'll run through the whole list, that's where we'll really suffer. Conditions where this may happen are when an ant is far away from the smells, so tuning the distance check and cutoff may helps to.

I want to see if I can get about 20 ants running around, that's the goal!


Post a Comment

<< Home