private IEnumerator CheckDashAttack() { while (true) { yield return(new WaitForSeconds(GetRandomCheckAttackDelay())); if (!ShouldCheckDashAttack(StateMachine_.Player)) { continue; } BattlePlayer target = BattlePlayerUtil.GetClosestEnemyPlayerFor(StateMachine_.Player, whereCondition: (otherPlayer) => { return(!AIUtil.DoesWallExistBetweenXZPoints(StateMachine_.Player.transform.position, otherPlayer.transform.position)); }); if (target == null) { continue; } Vector2 playerToTargetVector = BattlePlayerUtil.XZVectorFromTo(StateMachine_.Player, target); if (playerToTargetVector.magnitude <= kDashAggroDistance) { StateMachine_.SwitchState(AIStateMachine.State.DashAttack); } } }
private Vector3 GenerateValidDashDirection() { float predictedDashDistance = AIUtil.GetRandomPredictedDashDistance(); Vector3 playerPosition = StateMachine_.Player.transform.position; Vector3 lastDashDirection = Vector3.zero; for (int i = 0; i < GameConstants.Instance.AIPositionRetries; i++) { Vector3 dashDirection = UnityEngine.Random.insideUnitCircle.normalized; Vector3 dashEndPosition = playerPosition + (dashDirection * predictedDashDistance); lastDashDirection = dashDirection; if (!AIUtil.IsXZPositionOnPlatform(dashEndPosition) || AIUtil.DoesWallExistBetweenXZPoints(playerPosition, dashEndPosition)) { continue; } return(dashDirection); } Debug.LogWarning("Using invalid dash direction!", context: StateMachine_.Player); return(lastDashDirection); }