//------------------------------------------------------------------------------------------------------------------------------- //逃げる----------------------------------------------------------------------------------- void Escape( ) { //目的地に到達していたら次の目的地を探す if (_arrival) { //バグ回避のため最初だけ強制的に逃げる場所を決める--------------------------------------------------------------------- if (!_initial_destination) { _escape_area_num = Random.Range(0, _escape_area.Length); GameObject initial_escape_area = _escape_area[_escape_area_num].gameObject; int initial_escape_point_num = Random.Range(0, initial_escape_area.transform.childCount); GameObject initial_escape_point = initial_escape_area.transform.GetChild(initial_escape_point_num).gameObject; _escape_point = initial_escape_point.GetComponent <EscapePoint>( ); _agent.SetDestination(initial_escape_point.transform.position); _initial_destination = true; } //--------------------------------------------------------------------------------------------------------------------- //怪獣が居ないエリアを探す------------------------------------------- int count = 0; //ループで探す回数(バグ回避用) do { _escape_area_num = Random.Range(0, _escape_area.Length); count++; if (count > 10) { return; } } while (_escape_area[_escape_area_num].getIntrusionArea( )); //---------------------------------------------------------------- //見つけたエリアのGameObjectを取得 GameObject escape_area = _escape_area[_escape_area_num].gameObject; //見つけたエリアのポイントをランダムに決定 int escape_point_num = Random.Range(0, escape_area.transform.childCount); //見つけたエリアのポイントの情報を取得 GameObject escape_point = escape_area.transform.GetChild(escape_point_num).gameObject; _escape_point = escape_point.GetComponent <EscapePoint>( ); //ポイントまで逃げる _agent.SetDestination(escape_point.transform.position); //目的地に着いていないことにする _enemy_anim_ctrl.setWalkAnimFlag(true); //移動アニメーションフラグを立てる _arrival = false; } //ポイントに入ったらに変更する if (_escape_point.getIntrusionPoint( )) { _enemy_anim_ctrl.setWalkAnimFlag(false); //移動アニメーションフラグを消す _arrival = true; //目的地についたことにする } }
private void SetPoint(EscapePoint point) { _agent.isStopped = false; _agent.acceleration = _originalAcceleration; _currentPoint = point; transform.DOLookAt(_currentPoint.transform.position, _rotationSpeed); _agent.SetDestination(_currentPoint.transform.position); }
protected override void CustomUpdate() { if (_isThinking) { return; } if (_isStunned) { return; } if (IsRunCompleted() && _currentPoint != null) { _agent.isStopped = true; _agent.velocity = Vector3.zero; _agent.acceleration = 0; aiAnimation.SetBool("isRunning", false); aiAnimation.SetBool("isWalking", false); aiAnimation.SetBool("isStunned", false); _previousPoint = _currentPoint; _currentPoint = null; } Vector3 dir = GetPlayerDirection(); if (IsAlerted && _currentPoint == null) { aiAnimation.SetBool("isRunning", true); aiAnimation.SetBool("isWalking", false); aiAnimation.SetBool("isStunned", false); OnStateChanged?.Invoke(AIState.Alerted); SetPoint(GetRandomPoint(GetPointsByDistance(_escapePointRadius), dir)); } else if (!IsAlerted && _currentPoint == null) { // Idle if (Random.Range(0, 100) <= _idlePercentage) { aiAnimation.SetBool("isRunning", false); aiAnimation.SetBool("isWalking", false); aiAnimation.SetBool("isStunned", false); OnStateChanged?.Invoke(AIState.Idle); StartCoroutine(PerformIdle()); } else { // Walk aiAnimation.SetBool("isWalking", true); aiAnimation.SetBool("isRunning", false); aiAnimation.SetBool("isStunned", false); OnStateChanged?.Invoke(AIState.Walk); var list = GetPointsByDistance(_escapePointRadius); SetPoint(list[Random.Range(0, list.Count)]); } } aiAnimation.speed = _agent.speed / 2; }