Example #1
0
        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);
                }
            }
        }
Example #2
0
        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);
        }
        private Vector3 GenerateRandomNearbyPosition()
        {
            Vector3 lastNearbyPosition = Vector3.zero;

            for (int i = 0; i < GameConstants.Instance.AIPositionRetries; i++)
            {
                Quaternion randomDirection = Quaternion.Euler(new Vector3(0.0f, UnityEngine.Random.Range(0.0f, 360.0f), 0.0f));
                Vector3    nearbyPosition  = stateMachine_.Player.transform.position + (randomDirection * Vector3.forward * UnityEngine.Random.Range(kNearDistanceMin, kNearDistanceMax));

                lastNearbyPosition = nearbyPosition;

                if (!AIUtil.IsXZPositionOnPlatform(nearbyPosition))
                {
                    continue;
                }

                return(nearbyPosition);
            }

            Debug.LogWarning("Using invalid nearby position!", context: stateMachine_.Player);
            return(lastNearbyPosition);
        }
        protected override void OnStateEntered()
        {
            predictedDashDistance_ = AIUtil.GetRandomPredictedDashDistance();

            target_ = BattlePlayerUtil.GetClosestEnemyPlayerFor(StateMachine_.Player);
        }