Example #1
0
 //Update senses every few frames instead of every frame
 //add Time.deltaTime to a float every frame even if i don't update that frame.
 //This is to accumulate the correct values that will be used to multiply with, instead of Time.deltaTime
 void Start()
 {
     m_LayerMask         = ~CLayers.GetLayerMask_EnemyAndWeapon(); //layermask to ignore collisions with EnemyLayer and Weapon Layer
     m_AI                = GetComponent <CAI>();
     m_Player            = CPlayerControlls.GetPlayer();
     m_fCurrentSightCone = m_fNormalSightCone;
     if (m_Head == null)
     {
         print("Error: Variable m_Head of " + gameObject.name + " prefab was NULL!");
         m_Head = transform;
     }
 }
Example #2
0
    void SetActiveAI()
    {
        m_List_ActiveAI.Clear();
        Vector3 playerPos = CPlayerControlls.GetPlayer().transform.position;

        for (int i = 0; i < m_List_AllAI.Count; i++)
        {
            if (Vector3.Distance(m_List_AllAI[i].transform.position, playerPos) < m_fAIUpdateRange)
            {
                m_List_ActiveAI.Add(m_List_AllAI[i]);
                m_List_AllAI[i].AISetActive(true);
            }
            else
            {
                m_List_AllAI[i].AISetActive(false);
            }
        }
    }
Example #3
0
    public static void Alert(Vector3 originPos, float noiseRadius)
    {
        bool hasEnemies = Physics.CheckSphere(originPos, noiseRadius, m_LayerMask); //, QueryTriggerInteraction.Ignore

        if (hasEnemies)
        {
            Collider[] AIColliders = Physics.OverlapSphere(originPos, noiseRadius, m_LayerMask); //, QueryTriggerInteraction.Ignore
            Vector3    PlayerPos   = CPlayerControlls.GetPlayer().transform.position;
            for (int i = 0; i < AIColliders.Length; ++i)
            {
                if (AIColliders[i].gameObject.activeInHierarchy == true)
                {
                    AIColliders[i].GetComponent <CSenses>().Listen(PlayerPos);
                    AIColliders[i].GetComponent <CAI>().SetCombatPreviousFrame(true); //avoid playing alert message
                }
            }
        }
    }
Example #4
0
 // Update is called once per frame
 void Update()
 {
     m_fUpdateTimer += Time.deltaTime;
     if (m_fUpdateTimer > m_fUpdateActiveAIFrequency)
     {
         SetActiveAI();
         m_fUpdateTimer = 0;
     }
     if (Input.GetKeyDown(KeyCode.Space))
     {
         for (int i = 0; i < m_List_ActiveAI.Count; ++i)
         {
             m_List_ActiveAI[i].GetComponent <CAIAttack>().Cleanup();
             Vector3 dir = m_List_ActiveAI[i].transform.position - CPlayerControlls.GetPlayer().transform.position;
             m_List_ActiveAI[i].GetComponent <CStatusEffects>().Knockback(dir, 1500);
             //m_ListActiveAI[i].GetComponent<CHealth>().TakeDamage(1000);
         }
         SetActiveAI();
     }
 }
Example #5
0
    void Initialize()
    {
        if (m_bInitialized == false)
        {
            m_vPointOfInterest   = Vector3.zero;
            m_fSecToGenerateDest = m_fSecToGenerateDestBase;

            m_Health = GetComponent <CHealth>();

            m_Agent = GetComponent <NavMeshAgent>();
            if (GetAgent().stoppingDistance == 0)
            {
                GetAgent().stoppingDistance = 1.5f;
                m_fSpeedOriginal            = GetAgent().speed;
            }

            //m_Animator = GetComponent<Animator>();
            m_StatusEffects = GetComponent <CStatusEffects>();

            m_Senses = GetComponent <CSenses>();

            //m_Animations = GetComponent<CAnimations>();

            m_fLoseSightTimer = m_Senses.GetTimeUntilLoseSight();

            m_AIAttack = GetComponent <CAIAttack>();

            if (GetComponentInChildren <CSmokeVFX>())
            {
                m_SmokeVFX = GetComponentInChildren <CSmokeVFX>();
            }
            m_PlayerTransform = CPlayerControlls.GetPlayer().transform;

            m_Animator = GetComponent <Animator>();

            GetAnimator().keepAnimatorControllerStateOnDisable = true;

            m_bInitialized = true;
        }
    }
Example #6
0
    public void Update()
    {
        //print(gameObject.name + "'s state :" + m_eInternalState);
        if (gameObject.activeInHierarchy == false)
        {
            //print( gameObject.name + " is not active and Triggered a failsafe here." );
            return;
        }

        if (GetHealth().GetIsAlive() == false)
        {
            //Death stuff, cleanups etc
            OnDeath();
            return;
        }

        if (GetAgent().enabled == false)
        {
            //print( gameObject.name + "'s agent is not enabled and Triggered a failsafe here." );
            return;
        }

        OnUpdateStarted();

        if (GetAIAttack().GetIsAttacking() == true || m_bStationary == true)
        {
            m_bCanMove = false;
        }

        if (GetAgent().hasPath == true)
        {
            if (GetStatusEffects().GetIsPushed() == false)
            {
                if (transform.position != GetPreviousPosition())
                {
                    SetIsMoving(true);
                }
            }
        }

        /////INVESTIGATE POI/////
        if (GetCombat() == false)
        {
            if (GetCombatPreviousFrame() == true)
            {
                m_Senses.SetSightCone(m_Senses.GetNormalSightCone());
            }
            if (HasPOI() == true)
            {
                SetState(State.Investigate);
            }
        }
        /////INVESTIGATE POI/////
        else //GetCombat == true
        {
            if (GetCombatPreviousFrame() == false)
            {
                m_Senses.SetSightCone(m_Senses.GetCombatSightCone());
                CAIManager.AddToCombatList(this);
                CSoundBank.Instance.AIEnterCombat(GetAIType(), gameObject);
                //Alert enemies nearby and Engage
                //print("ALERT CODE WAS RUN");
                CNoiseSystem.Alert(CPlayerControlls.GetPlayer().transform.position, m_fAlertNoise);
            }
            //Attack state
            SetState(State.Attack);
        }

        UpdateAnimations();

        switch (m_eState)
        {
        case State.Idle:
        {
            //WANDER interaction
            m_fIdleTimer += Time.deltaTime;
            if (m_fIdleTimer >= m_fSecToGenerateDest)
            {
                if (m_bStationary == false)
                {
                    SetState(State.Wander);
                }
                //else remain in idle
            }
        }
        break;

        case State.Wander:
        {
            //IDLE interaction
            if (DestinationReached() == true)
            {
                SetState(State.Idle);
            }
        }
        break;

        case State.Investigate:
        {
            //play investigation emote
            //investigate walk?
            if (DestinationReached() == true)
            {
                if (RotateAIBool(GetPOI(), 0.90f) == true)
                {
                    TryResetPath();
                }
                //On reach destination, rotate head for a couple of seconds, then return?
            }
            if (GetIsMoving() == false)
            {
                m_fInvestigateTimer += Time.deltaTime;
                if (m_fInvestigateTimer > m_fInvestigateDuration)
                {
                    ///m_fInvestigateTimer = 0.0f;
                    ResetPOI();
                    if (m_bStationary == true)
                    {
                        SetState(State.Idle);
                    }
                    else
                    {
                        SetState(State.Wander);
                    }
                }
            }
        }
        break;

        case State.Wait:
            break;

        case State.Attack:
        {
            if (Vector3.Distance(transform.position, m_PlayerTransform.position) <= GetAIAttack().GetAttackRange())            //m_fAttackRange )
            {
                TryResetPath();
                if (GetAIAttack().GetCanAttack() == true)
                {
                    if (GetAttackStyle() == AttackStyle.Melee)
                    {
                        if (RotateAIBool(m_PlayerTransform.position, 0.90f) == true)
                        {
                            if (GetAIType() == AIType.Orc)
                            {
                                int iRandom;
                                iRandom = Random.Range(0, 2);         //means 0 to 1
                                GetAIAttack().Attack(iRandom);
                                CSoundBank.Instance.AIMelee(m_eAIType, iRandom, gameObject);
                            }
                            else
                            {
                                GetAnimator().SetBool("Collided", false);
                                GetAIAttack().Attack(0);
                                CSoundBank.Instance.GoblinMeleeAttack(gameObject);
                            }
                        }
                    }
                    else
                    {
                        if (RotateAIBool(m_PlayerTransform.position, 0.3f))
                        {
                            GetAIAttack().Attack(m_PlayerTransform.position);
                            //CSoundBank.Instance.GoblinRangedAttack(gameObject);
                        }
                    }
                }
                if (GetAIAttack().GetIsAttacking() == false)
                {
                    RotateAI(m_PlayerTransform.position);
                }
            }
            else
            {
                TrySetDestination(m_PlayerTransform.position);
                //print("Running toward player in Combat mode");
                if (m_bStationary == false)
                {
                    TrySetDestination(GetPOI());
                }
                else
                {
                    RotateAI(GetPOI());
                }
            }
        }
        break;

        default:
            break;
        }
        OnUpdateFinished();
    }