示例#1
0
        void UpdateCurrentAiState()
        {
            // Handle logic
            switch (AiState)
            {
            case AIState.Attack:
                bool mustShoot = Time.time > m_TimeStartedDetection + DetectionFireDelay;
                // Calculate the desired rotation of our turret (aim at target)
                Vector3 directionToTarget =
                    (m_EnemyController.KnownDetectedTarget.transform.position - TurretAimPoint.position).normalized;
                Quaternion offsettedTargetRotation =
                    Quaternion.LookRotation(directionToTarget) * m_RotationWeaponForwardToPivot;
                m_PivotAimingRotation = Quaternion.Slerp(m_PreviousPivotAimingRotation, offsettedTargetRotation,
                                                         (mustShoot ? AimRotationSharpness : LookAtRotationSharpness) * Time.deltaTime);

                // shoot
                if (mustShoot)
                {
                    Vector3 correctedDirectionToTarget =
                        (m_PivotAimingRotation * Quaternion.Inverse(m_RotationWeaponForwardToPivot)) *
                        Vector3.forward;

                    m_EnemyController.TryAtack(TurretAimPoint.position + correctedDirectionToTarget);
                }

                break;
            }
        }
示例#2
0
        void UpdateCurrentAiState()
        {
            // Handle logic
            switch (AiState)
            {
            case AIState.Patrol:
                m_EnemyController.UpdatePathDestination();
                m_EnemyController.SetNavDestination(m_EnemyController.GetDestinationOnPath());
                break;

            case AIState.Follow:
                m_EnemyController.SetNavDestination(m_EnemyController.KnownDetectedTarget.transform.position);
                m_EnemyController.OrientTowards(m_EnemyController.KnownDetectedTarget.transform.position);
                m_EnemyController.OrientWeaponsTowards(m_EnemyController.KnownDetectedTarget.transform.position);
                break;

            case AIState.Attack:
                if (Vector3.Distance(m_EnemyController.KnownDetectedTarget.transform.position,
                                     m_EnemyController.DetectionModule.DetectionSourcePoint.position)
                    >= (AttackStopDistanceRatio * m_EnemyController.DetectionModule.AttackRange))
                {
                    m_EnemyController.SetNavDestination(m_EnemyController.KnownDetectedTarget.transform.position);
                }
                else
                {
                    m_EnemyController.SetNavDestination(transform.position);
                }

                m_EnemyController.OrientTowards(m_EnemyController.KnownDetectedTarget.transform.position);
                m_EnemyController.TryAtack(m_EnemyController.KnownDetectedTarget.transform.position);
                break;
            }
        }