# Why does my AI Enemy slide towards its target when it is supposed to be idle?

So using Unity standard assets to get a stage rolling, Ive built a simple terrain and used FPSController as the player and AI ThirdPersonController (Ethan) as the enamy.

Ive built the navmesh and everything was working in its default state, but then I changed the AI script slightly as I wanted Ethan to follow me only if I come within a certain range, so I changed it to the following:

public float dangerRadius = 5f;

private void Start()
{
// get the components on the object we need ( should not be null due to require component so no need to check )
agent = GetComponentInChildren<UnityEngine.AI.NavMeshAgent>();
character = GetComponent<ThirdPersonCharacter>();

agent.updateRotation = false;
agent.updatePosition = true;
}

private void Update()
{
if (target != null)
agent.SetDestination(target.position);

character.Move(agent.desiredVelocity, false, false);

else
character.Move(Vector3.zero, false, false);
}

public void SetTarget(Transform target)
{
this.target = target;
}


But the problem is that when the remainingDistance is greater than dangerRadius or when I am out of range, Ethan just slides slowly towards the target in idle state and as the distance becomes lower than the threshold he starts running as expected.

Ive tried adding friction materials to the terrain and the collider on Ethan but he still slides.

Help thanks

• What happens if you comment out the else block? – Draco18s no longer trusts SE May 16 '18 at 1:30
• Still slides towards target :( – StuckInPhD May 16 '18 at 8:38
• Have you tried to comment out both (the second if and its else) to see if the sliding remains? – Nikaas May 16 '18 at 9:20
• removing both if and else does not help, he is still sliding towards me – StuckInPhD May 16 '18 at 20:34