public override void Execute() { // calculate direction currentPointIndex = path.GetRequiredIndex(enemy.transform.position, currentPointIndex); Vector3 target = path.GetPoint(currentPointIndex); Vector3 current = enemy.transform.position; Vector3 direction = target - current; float sqrDist = direction.sqrMagnitude; direction.Normalize(); // calculate speed currentSpeed = speed; if (sqrDist <= slowDownDistance * slowDownDistance) { float dist = Mathf.Sqrt(sqrDist); currentSpeed = speed * (dist / slowDownDistance); } // move enemy enemy.transform.position = current + direction * currentSpeed * Time.deltaTime; }