public override void UpdateComponent(float _DeltaTime)
    {
        base.UpdateComponent(_DeltaTime);
        if (!m_AICharacter)
        {
            return;
        }
        if (m_AICharacter.m_TargetCharacter)
        {
            return;
        }

        if (m_AICharacter.m_UpperAnimState == CharacterBase.E_UpperBodyAnimState.ATTACK)
        {
            m_AICharacter.m_UpperAnimState = CharacterBase.E_UpperBodyAnimState.IDLE;
            m_AICharacter.m_Animator.CrossFade(CharacterBase.m_AnimIdleKey, 0.1f);
            m_AICharacter.GetNavMeshController().ClearPath();
        }

        if (m_AICharacter.GetAIState() != AICharacter.E_AIState.PATROL)
        {
            m_AICharacter.SetAIState(AICharacter.E_AIState.PATROL);
        }

        if (m_AICharacter.GetNavMeshController().IsUpdate())
        {
            return;
        }
        if (m_PositionHoldingTimer > 0.0f)
        {
            m_PositionHoldingTimer -= _DeltaTime;
            return;
        }

        m_PositionHoldingTimer = m_AICharacter.GetAIData().PositionHoldingTime;

        float   minradius    = m_AICharacter.GetAIData().MinimumMovingRange;
        float   maxradius    = m_AICharacter.GetAIData().MaxmumMovingRange;
        float   findrange    = maxradius - minradius;
        Vector3 nextlocation = new Vector3(Random.Range(-findrange, findrange), 0.0f, Random.Range(-findrange, findrange));

        nextlocation.x += nextlocation.x < 0.0f ? -minradius : minradius;
        nextlocation.z += nextlocation.z < 0.0f ? -minradius : minradius;
        m_AICharacter.GetNavMeshController().SetMoveLocation(m_AICharacter.transform.position, m_AICharacter.transform.position + nextlocation);
    }
Ejemplo n.º 2
0
    public override void Initialize(CharacterBase _CharacterBase)
    {
        base.Initialize(_CharacterBase);
        m_AICharacter = _CharacterBase as AICharacter;
        if (!m_AICharacter)
        {
            return;
        }

        m_AttackDelay       = m_AICharacter.GetAIData().AttackDelay;
        m_ObstacleLayerMask = 1 << LayerMask.NameToLayer("Ground") | 1 << LayerMask.NameToLayer("Obstacle");
        m_TargetLayerMask   = 1 << LayerMask.NameToLayer("PlayerCharacter") | 1 << LayerMask.NameToLayer("Ground") | 1 << LayerMask.NameToLayer("Obstacle") | 1 << LayerMask.NameToLayer("SpellObstacle");
    }
Ejemplo n.º 3
0
    public override void UpdateComponent(float _DeltaTime)
    {
        base.UpdateComponent(_DeltaTime);

        if (!m_AICharacter)
        {
            return;
        }
        if (m_AICharacter.m_Live == CharacterBase.E_Live.DEAD)
        {
            if (m_AICharacter.GetNavMeshController().IsUpdate())
            {
                m_AICharacter.GetNavMeshController().ClearPath();
            }
            return;
        }
        if (m_CharacterBase.m_UnderAnimState == CharacterBase.E_UnderBodyAnimState.JUMP)
        {
            return;
        }
        if (!m_AICharacter.GetNavMeshController().IsUpdate())
        {
            if (m_AICharacter.m_UnderAnimState == CharacterBase.E_UnderBodyAnimState.RUN)
            {
                m_AICharacter.m_Animator.SetFloat("DirectionX", 0.0f);
                m_AICharacter.m_Animator.SetFloat("DirectionY", 0.0f);
                m_AICharacter.m_UnderAnimState = CharacterBase.E_UnderBodyAnimState.LAND;
            }
            return;
        }

        if (m_AICharacter.m_UnderAnimState != CharacterBase.E_UnderBodyAnimState.RUN)
        {
            m_AICharacter.m_UnderAnimState = CharacterBase.E_UnderBodyAnimState.RUN;
            m_AICharacter.m_Animator.CrossFade(CharacterBase.m_UpperBodyTreeKey, 0.1f);
        }

        Vector3 dir = m_AICharacter.GetNavMeshController().GetCurrentPathDirection(m_CharacterBase.transform).normalized;

        m_AICharacter.m_Animator.SetFloat("DirectionX", dir.x);
        m_AICharacter.m_Animator.SetFloat("DirectionY", dir.z);
        m_AICharacter.GetNavMeshController().UpdateTransform(m_CharacterBase.transform, m_AICharacter.GetAIData().MoveSpeed, m_RotatePerSpeed, _DeltaTime);
    }
    public override void UpdateComponent(float _DeltaTime)
    {
        base.UpdateComponent(_DeltaTime);

        if (!m_AICharacter)
        {
            return;
        }
        if (m_AICharacter.m_Live == CharacterBase.E_Live.DEAD)
        {
            return;
        }

        float   rotValue    = m_RotatePerSpeed * _DeltaTime;
        Vector3 rot         = m_AICharacter.transform.eulerAngles;
        Vector3 focusingdir = Vector3.zero;

        if (m_AICharacter.m_TargetCharacter)
        {
            Vector3 dir  = (m_AICharacter.m_TargetCharacter.transform.position - m_AICharacter.transform.position).normalized;
            Vector3 cdir = dir;
            cdir.y = 0.0f;
            float dirAngle = Vector3.Angle(cdir, dir);

            m_AICharacter.SetUpperBodyAngleX(dir.y < 0.0f ? -dirAngle : dirAngle);
            m_AICharacter.UpperBodyYAngleOffsetPercentage = dir.magnitude / m_AICharacter.GetAIData().AttackRange;

            focusingdir = (m_AICharacter.m_TargetCharacter.transform.position - m_AICharacter.transform.position).normalized;
        }
        else if (m_AICharacter.GetNavMeshController().IsUpdate())
        {
            focusingdir = m_AICharacter.GetNavMeshController().GetCurrentPathDirection(m_AICharacter.transform).normalized;
        }

        if (focusingdir == Vector3.zero)
        {
            return;
        }

        float   dot    = Vector3.Dot(m_AICharacter.transform.right, focusingdir);
        Vector3 dirRot = Quaternion.LookRotation(focusingdir).eulerAngles;

        if (Mathf.Abs(dirRot.y - rot.y) > rotValue)
        {
            if (dot < 0.0f)
            {
                rot.y -= rotValue;
            }
            else
            {
                rot.y += rotValue;
            }
        }
        else
        {
            rot.y = dirRot.y;
        }
        rot.y = rot.y % 360.0f;

        m_AICharacter.transform.eulerAngles = rot;
    }
Ejemplo n.º 5
0
    public override void UpdateComponent(float _DeltaTime)
    {
        base.UpdateComponent(_DeltaTime);

        if (!m_AICharacter)
        {
            return;
        }
        if (m_AICharacter.m_Live == CharacterBase.E_Live.DEAD)
        {
            if (m_AICharacter.m_UpperAnimState == CharacterBase.E_UpperBodyAnimState.ATTACK)
            {
                m_AICharacter.m_UpperAnimState = CharacterBase.E_UpperBodyAnimState.DEATH;
                m_AICharacter.m_Animator.CrossFade(CharacterBase.m_AnimIdleKey, 0.1f);
            }
            return;
        }
        if (!m_AICharacter.m_TargetCharacter)
        {
            return;
        }

        if (m_AICharacter.GetAIState() != AICharacter.E_AIState.ATTACK)
        {
            return;
        }

        if (m_AICharacter.m_UpperAnimState != CharacterBase.E_UpperBodyAnimState.ATTACK)
        {
            m_AICharacter.m_UpperAnimState = CharacterBase.E_UpperBodyAnimState.ATTACK;
            m_CharacterBase.m_Animator.CrossFade(CharacterBase.m_AnimGunAttackKey, 0.1f * GameManager.Instance.TimeScale);
            m_AttackDelay = 0.1f;
        }

        if (m_AttackDelay > 0.0f)
        {
            m_AttackDelay -= _DeltaTime;
            return;
        }

        m_AttackDelay = m_AICharacter.GetAIData().AttackDelay;

        if (m_AICharacter.GetAIData().Belligerence < (1.0f - Random.Range(0.0f, 1.0f)))
        {
            m_AttackDelay += m_AICharacter.GetAIData().Belligerence *(1.0f - Random.Range(0.0f, 1.0f));
        }

        Vector3 upperbodyDir       = m_AICharacter.GetUpperBodyDirection();
        Vector3 upperbodyDirNormal = upperbodyDir.normalized;
        Vector3 targetDir          = m_AICharacter.m_TargetCharacter.transform.position - m_AICharacter.transform.position;
        float   tdistance          = targetDir.magnitude;
        float   d = Vector3.Dot(upperbodyDirNormal, targetDir.normalized);

        if (d > 0.95f && tdistance <= m_AICharacter.GetAIData().AttackRange)
        {
            if (Physics.Raycast(m_AICharacter.GetBodyPositionWithWorld(), upperbodyDirNormal, tdistance * 0.3f, m_ObstacleLayerMask))
            {
                foreach (Gun g in m_CharacterBase.GetGuns())
                {
                    g.GunShotDisable();
                }
                return;
            }

            foreach (Gun g in m_CharacterBase.GetGuns())
            {
                g.GunShotActivate();
            }
            for (int i = 0; i < m_AICharacter.GetGunAttachCount(); ++i)
            {
                BulletSystem.CreateBullet(m_AICharacter.GetGun(i).GetFirePoint().position, 1.0f,
                                          m_AICharacter.m_CharacterID, E_BulletType.ORANGE, 1, upperbodyDir, 30.0f, m_TargetLayerMask, 5);
            }
            SoundManager.Instance.PlayInstanceSound(m_CharacterBase.GetGun(0).GetFirePoint().position, m_CharacterBase.GetGun(0).GetFireSound());
        }
        else
        {
            foreach (Gun g in m_CharacterBase.GetGuns())
            {
                g.GunShotDisable();
            }
        }
    }
    public override void UpdateComponent(float _DeltaTime)
    {
        base.UpdateComponent(_DeltaTime);

        if (!m_AICharacter)
        {
            return;
        }
        if (!m_AICharacter.m_TargetCharacter)
        {
            return;
        }
        if (m_AICharacter.m_TargetCharacter.m_Live == CharacterBase.E_Live.DEAD)
        {
            m_AICharacter.m_TargetCharacter = null;
            m_AICharacter.GetNavMeshController().ClearPath();
            foreach (Gun g in m_CharacterBase.GetGuns())
            {
                g.GunShotDisable();
            }
            return;
        }

        if (m_HoldTimer > 0.0f)
        {
            m_HoldTimer -= _DeltaTime;
        }

        if (m_UpdateDelayTimeTimer > 0.0f)
        {
            m_UpdateDelayTimeTimer -= _DeltaTime;
            if (m_UpdateDelayTimeTimer > 0.0f)
            {
                return;
            }
        }

        m_UpdateDelayTimeTimer = m_UpdateDelayTime;

        Vector3 direction = m_AICharacter.m_TargetCharacter.transform.position - m_AICharacter.transform.position;
        float   distance  = direction.magnitude;

        if (m_AICharacter.GetAIData().AttackRange < distance)
        {
            m_AICharacter.GetNavMeshController().SetMoveLocation(m_AICharacter.transform.position, m_AICharacter.m_TargetCharacter.transform.position);
            m_AICharacter.m_UpperAnimState = CharacterBase.E_UpperBodyAnimState.IDLE;
            m_CharacterBase.m_Animator.CrossFade(CharacterBase.m_AnimIdleKey, 0.1f);
            m_AICharacter.SetAIState(AICharacter.E_AIState.CHASE);
            foreach (Gun g in m_CharacterBase.GetGuns())
            {
                g.GunShotDisable();
            }
        }
        else
        {
            if (m_AICharacter.GetAIState() != AICharacter.E_AIState.ATTACK)
            {
                m_AICharacter.SetAIState(AICharacter.E_AIState.ATTACK);
                m_AICharacter.GetNavMeshController().ClearPath();
            }

            if (m_AICharacter.GetNavMeshController().IsUpdate())
            {
                return;
            }

            if (m_HoldTimer > 0.0f)
            {
                return;
            }

            m_HoldTimer = Random.Range(m_AICharacter.GetAIData().PositionHoldingTime * 0.3f, m_AICharacter.GetAIData().PositionHoldingTime);

            float angle      = m_AICharacter.transform.eulerAngles.y;
            float b          = m_AICharacter.GetAIData().Belligerence;
            float offset     = (distance / m_AICharacter.GetAIData().AttackRange) * b * 90.0f;
            float fixedAngle = angle + Random.Range(-offset, offset);
            angle += angle < fixedAngle ? -(100.0f - offset) : 100.0f - offset;

            if (angle > 360.0f)
            {
                angle -= 360.0f;
            }
            else if (angle < 0.0f)
            {
                angle += 360.0f;
            }


            Vector3 fwd            = Quaternion.AngleAxis(angle, Vector3.up) * Vector3.forward;
            float   minrange       = m_AICharacter.GetAIData().MinimumMovingRange;
            float   travelDistance = Random.Range(minrange > 0.5f ? minrange : 0.5f, m_AICharacter.GetAIData().MaxmumMovingRange);
            m_AICharacter.GetNavMeshController().SetMoveLocation(m_AICharacter.transform.position, m_AICharacter.transform.position + fwd * travelDistance);
        }
    }