Hi there
I am writing a game with some basic AI elements. The enemies know there position and the players position and so are able to rotate and follow the player around etc.
The idea is that when an enemy gets within a radius of the player they calculate a new random angle and move that way for 3 seconds then continue following the player. The effect with a single enemy works fine and looks OK.
The next thing I need to do is if two enemies are near each other they produce a random angle and move away from each other for a small amount of time. If I don't do this then it is possible to have all the enemies running into each other and acting the same.
I foolishly haven't got my code with me but I am doing something like
for(int i = 0; i<numberOfEnemies; i++)
{
if(tooCloseToEnemy)
time = 3.0;
if(timeFactor >0.0)
float newAngle = rand()%90+45;
if(enemy[i].angle > newAngle)
{
enemy[i].angle -= 80*timeFactor
}
}
I think the problem is that all the enemies behave the same and so always collide and run into each other continuously once it first occurs.
Is there an easy or better way of doing a random variable within a for loop so that the two colliding enemies will have a different angle???
Many thanks sorry if its a bit of a vague question