public override void UpdateState(BotController bot) { var player = GameManager.Instance.Player; if (player == null || player.IsDead) { return; } bot.ResetWaypoints(); // We'll be using all the waypoints float minDotValue = float.MaxValue; Vector3 targetWP = bot.transform.position; bot.ForEachWaypoint(wp => // Get a waypoint that is in opposite direction to that of player { float dot = Vector3.Dot(wp - bot.transform.position, player.transform.position - bot.transform.position); if (dot < minDotValue) { minDotValue = dot; targetWP = wp; } }); bot.SetPathDestination(targetWP); bot.ShootDirection = player.transform.position - bot.transform.position; // Square distance calculation is faster and efficient if (bot.ShootDirection.sqrMagnitude < bot.maxShootDist * bot.maxShootDist) { bot.Shoot(); } }