コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        float distance = Vector3.Distance(target.position, transform.position);

        if (distance <= lookRadius)
        {
            enemyNav.MoveToTarget(target.position);

            if (distance <= agent.stoppingDistance)
            {
                FaceTarget();
            }
        }

        //walk
        float speedPercent = agent.velocity.magnitude / agent.speed;

        anim.SetFloat("speedPercent", speedPercent, locomotionAnimationSmootTime, Time.deltaTime);
    }
コード例 #2
0
    //--LOCOMOTION中のアクションをする関数
    void LocomotionAction( )
    {
        float distance = Vector3.Distance(_target.position, transform.position);

        //_targetの位置に移動する処理-----------------------------------------------------------------------------------------------------
        if (!_lockOn)                   //ロックオン前処理
        //視野内に_targetがいたら行動する処理-----------
        {
            if (_fieldOfView.IsInFieldOfView(_target))
            {
                _enemyNav.MoveToTarget(_target.position);
                if (distance <= _lockOnRadius)
                {
                    _lockOn = true;
                }
            }
            //---------------------------------------------
        }
        else                                    //ロックオン時処理
        {
            if (distance <= _lockOnRadius)
            {
                FaceTarget(_target);                    //向きを変えないと移動しないことがある(爆弾使用時)ので向きを変える処理
                _enemyNav.MoveToTarget(_target.position);
            }
            else
            {
                _lockOn = false;
            }
        }
        //加勢に入る処理------------------------------------------------------------------------------------------------
        for (int i = 0; i < _goblinList.Count; i++)
        {
            GoblinAnimationController goblinListAnim = _goblinList [i].GetComponent <EnemyController> ()._animController;
            if (goblinListAnim.CheckAttacking())
            {
                if (distance <= _assistRadius)
                {
                    _enemyNav.MoveToTarget(_target.position);
                    break;
                }
            }
        }
        //-------------------------------------------------------------------------------------------------------------
        //--------------------------------------------------------------------------------------------------------------------------------

        //至近距離時の処理-------------------------------------------------------------------------------
        if (distance <= _agent.stoppingDistance)
        {
            if (_fieldOfView.IsInFieldOfView(_target))                  //視野内にいる時のみ向きを変え、攻撃待機状態に
            {
                FaceTarget(_target);
                _animController.ChangeAttacking(true);
            }
        }
        //-----------------------------------------------------------------------------------------------


        //walk・idle・runアニメーション処理---------------------------------
        float speedPercent = _agent.velocity.magnitude * 5 / _agent.speed;

        _animController.MoveAnim(speedPercent);
        //-----------------------------------------------------------------

        //音に反応する処理----------------------------------------------------------------------------------------------------------------
        if (_agent.velocity.magnitude <= 0)                                   //移動してない時
        {
            int       count      = _soundReaction.GetAudioSourceList().Count; //_audioSountListの数
            Transform soundTrans = transform;                                 //聞こえた音のtransformを格納する変数
            bool      setFlag    = false;                                     //soundTransformに値を格納したか確認するフラグ
            //音が聞こえているか確認---------------------------------------------------------
            for (int i = 0; i < count; i++)
            {
                if (_soundReaction.Hear(i))
                {
                    Transform trans = _soundReaction.GetAudioSourceList() [i].transform;
                    if (!setFlag ||
                        Vector3.Distance(transform.position, trans.position) < Vector3.Distance(transform.position, soundTrans.position))                                       //より近い方をsoundTransformに格納
                    {
                        soundTrans = trans;
                        setFlag    = true;
                    }
                }
            }
            //-------------------------------------------------------------------------------
            //音の聞こえた方向を向く処理-----------------------------------------
            if (setFlag)
            {
                FaceTarget(soundTrans);
                Debug.Log(gameObject.name + " here " + soundTrans.gameObject);
            }
            //------------------------------------------------------------------
        }
        //-------------------------------------------------------------------------------------------------------------------------------
    }