I am butting my head against the wall but cannot find a way to make the enemies circle around my player. Actually, I want them to maintain distance from each other and also circle around my player ( sort of hit me and get back - like in assassin’s creed). If someone can help me with the code, I will be very thankful.
I already have the AI attacking me randomly but they huddle too close together.
This is a piece of code I am using to make ai decide when to attack and when to move towards me.
if(targetalive.alive==true && lifecheck.alive==true&& !animation.IsPlaying("hit"))
{
if(distance<4&&distance>=1.5)
{
MoveTowards(moveToward, walkSpeed);
animation.CrossFade("walk", 0.1);
}
else if (distance<30 && distance>4)
{
MoveTowards(moveToward, runSpeed);
animation.CrossFade("run", 0.1);
}
else if (distance<1.5 && distance >=1.3)
{
attackRate = Random.Range(2.0,4.0);
if(Time.time > nextAttackAllowed && !animation.IsPlaying("block"))
{
doNextAnim();
timeOfLastAttack = Time.time;
nextAttackAllowed = timeOfLastAttack + attackRate;
}
}
else if (distance <1.3)
{
SlamBack (slamDirection * 1.2);
}
else
{
animation.CrossFade("idle", 0.1);
}
}
else if (lifecheck.alive==true && !animation.IsPlaying("hit"))
{
animation.CrossFade("idle", 0.1);
}