Exemplo n.º 1
0
    //ロッカーに隠れる
    private void HiddenLocker()
    {
        //ロッカーアニメーションとSEを再生、Colliderの調整
        _lockerDoorAnim.SetTrigger("Hide");
        _audioSource.PlayOneShot(_locker);
        _lockerDoorCollition.isTrigger = true;
        _lockerParentCollision.enabled = false;

        //プレイヤーのタグを変更し追跡対象から外す、ロッカーの中に位置を移動
        _playerObject.tag = "HideArea";
        _hide.y           = _playerObject.transform.position.y;
        _playerObject.transform.position = _hide;
        _playerObject.transform.rotation = gameObject.transform.rotation;

        //走り状態を解除してからキーボードを操作不能にする
        if (_playerController.Running)
        {
            _playerController.Running    = false;
            _playerController.WalkSpeed /= _playerController.RunSpeed;
        }
        _playerController.enabled = false;

        //敵の追跡状態を解除
        if (_enemyObject != null)
        {
            if (_enemyBrain.Chasing)
            {
                _enemyBrain.PatrolMode();
                _enemy.SetPatrolPoint();
            }
            if (_enemyBrain.ChasePlayer)
            {
                _enemyBrain.ChasePlayer = false;
            }
        }
    }
Exemplo n.º 2
0
    private void Update()
    {
        if (_agent.pathPending)
        {
            _move.Set(0.0f, 0.0f, 0.0f);
        }
        else
        {
            //次の目標座標を確認
            _targetCorner = LastCorner;
            _speed        = _walkSpeed * Time.unscaledDeltaTime;
            for (int i = 0; i < _agent.path.corners.Length; i++)
            {
                _targetCorner = _agent.path.corners[i];
                if (DistanceXZ(_targetCorner, gameObject.transform.position) >= _speed)
                {
                    break;
                }
            }

            //移動方向と速度の算出
            _move   = _targetCorner - gameObject.transform.position;
            _move.y = 0.0f;
            _rotate = _angularSpeed * Time.deltaTime;

            //角度と移動設定
            if (!IsReached)
            {
                _angle = Vector3.SignedAngle(gameObject.transform.forward, _move, Vector3.up);

                if (Mathf.Abs(_angle) > _turnAngle)
                {
                    _rotateMax = _turnAnguleSpeed * Time.deltaTime;
                    _rotate    = Mathf.Min(Mathf.Abs(_angle), _rotateMax);
                    gameObject.transform.Rotate(0.0f, _rotate * Mathf.Sign(_angle), 0.0f);
                    _move  = Vector3.zero;
                    _speed = 0.0f;
                }
                else
                {
                    if (_move.magnitude < _speed)
                    {
                        _speed  = _move.magnitude;
                        _rotate = _angle;
                        gameObject.transform.Rotate(0.0f, _angle, 0.0f);
                    }
                    else
                    {
                        _rotate = Mathf.Min(Mathf.Abs(_angle), _rotate);
                        gameObject.transform.Rotate(0.0f, _rotate * Mathf.Sign(_angle), 0.0f);
                    }

                    _move = gameObject.transform.forward * _speed;
                }
            }
            else
            {
                //次の巡回ポイントの設定
                _speed  = 0.0f;
                _move   = LastCorner - gameObject.transform.position;
                _move.y = 0.0f;

                if (_enemyBrain.Chasing)
                {
                    _enemyBrain.PatrolMode();
                }
                SetPatrolPoint();
            }

            //移動
            gameObject.transform.position += _move;
        }
    }