# The A,I can't seems to move/strafe on the left continously?

 void Update()
{
ChasingPlayer();
}

void ChasingPlayer()
{
if (chasing == true)
{
transform.LookAt(player.transform);  //facing player
transform.position += transform.forward * approaching * Time.deltaTime;  //going towards player
}

float distance = Vector3.Distance(transform.position, player.position);
Debug.Log(distance); //calculating the distance between player and enemy
if(distance < 10)
{
chasing = false;
transform.position += Vector3.left * 2f * Time.deltaTime;
Debug.Log("STOP!");
}
}


I want my A.I to approach to the player but when it reaches within 10 feet(?), I want it to stop moving towards the player and strafe/move to the left or right from there but instead it just moving in a curve movement that leads towards the player. How should i stop the AI within 10 feet(?) and move to the left/right?

• When/how do you set the chasing flag to true? – Vaillancourt Jul 27 at 15:21
• Note that an animated gif would help a lot get what's going on :) – Vaillancourt Jul 27 at 15:23

transform.position += Vector3.left * 2f * Time.deltaTime;

Vector3.left is a world-space direction; it does not take the enemy's current rotation into account. Perhaps what you want is this:
transform.position += transform.right * 2f * Time.deltaTime; //to go right

transform.position -= transform.right * 2f * Time.deltaTime; //to go left