妥協案
慣性をゼロにして蜘蛛と重ならないようにする
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
using UnityEngine;
|
||||
|
||||
// ==========================================
|
||||
// ■ STATE: IDLE (待機状態)
|
||||
// ==========================================
|
||||
public class SpiderIdleState : ISpiderState
|
||||
{
|
||||
private BossController boss;
|
||||
@@ -23,15 +20,6 @@ public class SpiderIdleState : ISpiderState
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// ■ STATE: CHASE (追跡・行動分岐状態)
|
||||
// ==========================================
|
||||
// ==========================================
|
||||
// ■ STATE: CHASE (追跡・行動分岐状態) - 13x13ステージ最適化版
|
||||
// ==========================================
|
||||
// ==========================================
|
||||
// ■ STATE: CHASE (遠距離即座突進・最適化版)
|
||||
// ==========================================
|
||||
public class SpiderChaseState : ISpiderState
|
||||
{
|
||||
private BossController boss;
|
||||
@@ -47,7 +35,7 @@ public class SpiderChaseState : ISpiderState
|
||||
|
||||
float distance = Vector3.Distance(boss.transform.position, boss.Player.position);
|
||||
|
||||
// ─── ★最優先判定:遠距離(6m以上)かつクールダウン終了 ➔ 1歩も歩かずに即突進 ───
|
||||
// 6m以上かつクールダウン終了 ➔ 1歩も歩かずに即突進
|
||||
if (distance >= boss.chargeMinimumDistance && boss.ChargeCooldownTimer <= 0f)
|
||||
{
|
||||
boss.ChangeState<SpiderChargeState>();
|
||||
@@ -61,15 +49,13 @@ public class SpiderChaseState : ISpiderState
|
||||
return;
|
||||
}
|
||||
|
||||
// 判定3:中間距離(2.5m~6m)、または遠距離だけどクールダウン中の場合
|
||||
// 💡 ここで初めて「通常歩き(Walk)」でじりじりとプレイヤーに近づきます
|
||||
boss.Agent.SetDestination(boss.Player.position);
|
||||
boss.Anim.SetFloat("Speed", boss.Agent.velocity.magnitude);
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// ■ STATE: BITE (通常噛みつき - パリィ可)
|
||||
// ■ STATE: BITE (完全足止め・めり込み防止版)
|
||||
// ==========================================
|
||||
public class SpiderBiteState : ISpiderState
|
||||
{
|
||||
@@ -80,31 +66,33 @@ public class SpiderBiteState : ISpiderState
|
||||
|
||||
public void EnterState()
|
||||
{
|
||||
stateTimer = 1.5f; // 攻撃アニメーションの想定想定想定
|
||||
stateTimer = 1.5f;
|
||||
|
||||
// ★超重要:噛みつきモーションに入った瞬間、移動を「完全強制停止」してめり込みを防ぐ
|
||||
boss.Agent.isStopped = true;
|
||||
boss.Agent.velocity = Vector3.zero; // 慣性もゼロにする
|
||||
|
||||
boss.Anim.SetTrigger("Attack_Bite");
|
||||
Debug.Log("🎯 蜘蛛ボス:噛みつき攻撃!(パリィ受付中)");
|
||||
Debug.Log("🎯 蜘蛛ボス:噛みつき攻撃!(その場に完全固定)");
|
||||
}
|
||||
|
||||
public void ExitState() { }
|
||||
public void ExitState()
|
||||
{
|
||||
// ステートを出るときに停止ロックを解除する
|
||||
boss.Agent.isStopped = false;
|
||||
}
|
||||
|
||||
public void UpdateState()
|
||||
{
|
||||
stateTimer -= Time.deltaTime;
|
||||
if (stateTimer <= 0f)
|
||||
{
|
||||
// 攻撃が終わったら、フェーズ移行チェックを挟みつつ追跡に戻る
|
||||
if (boss.PendingUltimate) boss.ChangeState<SpiderJumpToCeilingState>();
|
||||
else boss.ChangeState<SpiderChaseState>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// ■ STATE: CHARGE (走って体当たり突進 - パリィ可)
|
||||
// ==========================================
|
||||
// ==========================================
|
||||
// ■ STATE: CHARGE (咆哮・溜めロック ➔ ロケット発射)
|
||||
// ==========================================
|
||||
public class SpiderChargeState : ISpiderState
|
||||
{
|
||||
private BossController boss;
|
||||
@@ -117,89 +105,86 @@ public class SpiderChargeState : ISpiderState
|
||||
|
||||
public void EnterState()
|
||||
{
|
||||
roarTimer = 1.5f; // 咆哮・溜めロックの時間(1.5秒)
|
||||
roarTimer = 1.5f; // 溜め(咆哮)時間
|
||||
chargeTimer = boss.chargeDuration;
|
||||
isChargingPhase = false;
|
||||
|
||||
boss.Agent.enabled = false; // その場に固定するためNavMeshを即オフ
|
||||
boss.ResetChargeCooldown(); // 突進のクールダウンを開始
|
||||
// ★重要:突進の溜め中は、NavMeshAgentの自動移動を「一時停止」にしてその場に固定する
|
||||
boss.Agent.isStopped = true;
|
||||
boss.ResetChargeCooldown();
|
||||
|
||||
// 1. 遠距離を検知した「その場」で、即座に咆哮威嚇を再生
|
||||
boss.Anim.SetTrigger("Attack_Roar");
|
||||
Debug.Log("🔊 蜘蛛ボス:【遠距離検知】その場で咆哮・突進の溜めを開始!");
|
||||
Debug.Log("🔊 蜘蛛ボス:その場で突進の溜め(咆哮)開始");
|
||||
}
|
||||
|
||||
public void ExitState()
|
||||
{
|
||||
boss.Anim.SetBool("IsCharging", false);
|
||||
boss.Agent.enabled = true;
|
||||
|
||||
// ★重要:突進ステートを出るときは、スピードと加速を通常のザコ敵・巡回時の値に必ず戻す
|
||||
boss.Agent.speed = boss.NormalSpeed;
|
||||
boss.Agent.acceleration = boss.NormalAcceleration;
|
||||
boss.Agent.isStopped = false;
|
||||
}
|
||||
|
||||
public void UpdateState()
|
||||
{
|
||||
// ─── フェーズ1:咆哮・溜め(動かずプレイヤーの方向を完全にロック) ───
|
||||
// ─── フェーズ1:咆哮・溜めロックオン(その場で旋回のみ) ───
|
||||
if (!isChargingPhase)
|
||||
{
|
||||
roarTimer -= Time.deltaTime;
|
||||
|
||||
// プレイヤーが動いても、突進直前までずーーっとその方向を向いてロックオンし続ける
|
||||
if (boss.Player != null)
|
||||
{
|
||||
Vector3 lookDir = (boss.Player.position - boss.transform.position).normalized;
|
||||
lookDir.y = 0;
|
||||
if (lookDir != Vector3.zero)
|
||||
{
|
||||
// 凄まじい速度でプレイヤーを正面に捉え続ける
|
||||
boss.transform.rotation = Quaternion.Slerp(boss.transform.rotation, Quaternion.LookRotation(lookDir), Time.deltaTime * 10f);
|
||||
}
|
||||
}
|
||||
|
||||
// 溜め時間が終わったら「発射」
|
||||
// 溜め終了 ➔ 「発射」の瞬間
|
||||
if (roarTimer <= 0f)
|
||||
{
|
||||
isChargingPhase = true;
|
||||
boss.Anim.SetTrigger("ChargeStart");
|
||||
boss.Anim.SetBool("IsCharging", true);
|
||||
|
||||
// 発射した瞬間のプレイヤーのベクトルを最終確定(ロック完了)
|
||||
// 1. 発射する直線ベクトルを確定
|
||||
if (boss.Player != null)
|
||||
{
|
||||
chargeDirection = (boss.Player.position - boss.transform.position).normalized;
|
||||
chargeDirection.y = 0;
|
||||
boss.transform.rotation = Quaternion.LookRotation(chargeDirection);
|
||||
}
|
||||
Debug.Log("🚀 蜘蛛ボス:ロックオン完了、全速力で発射!");
|
||||
|
||||
// 2. ★プロの技:ボスの正面方向の「遥か彼方(例: 20m先)」に、突進の目的地座標を計算
|
||||
Vector3 targetDestination = boss.transform.position + chargeDirection * 20f;
|
||||
|
||||
// 3. ★移動をNavMeshAgentに一任する(超高速化)
|
||||
boss.Agent.isStopped = false; // 移動再開
|
||||
boss.Agent.speed = boss.chargeSpeed; // スピードを全速力(14fなど)に
|
||||
boss.Agent.acceleration = 120f; // 即座に最高速に達するように加速を爆上げする
|
||||
|
||||
// 目的地を設定(NavMeshの壁やプレイヤーのCharacterControllerを考慮して自動で進むようになる)
|
||||
boss.Agent.SetDestination(targetDestination);
|
||||
|
||||
Debug.Log("🚀 蜘蛛ボス:NavMesh突進ダッシュ発射!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// ─── フェーズ2:発射(端から端まで全速力ダッシュ) ───
|
||||
|
||||
// 【安全対策:レイキャストによる壁検知】
|
||||
// 13x13ステージの端(壁や柱)に激突してめり込むのを防ぐため、ボスの目の前1.5mに障害物がないかチェック
|
||||
Ray ray = new Ray(boss.transform.position + Vector3.up * 0.5f, chargeDirection);
|
||||
if (Physics.Raycast(ray, 1.5f))
|
||||
{
|
||||
Debug.Log("🔒 蜘蛛ボス:ステージの端(壁)を検知したため、突進を安全に終了します。");
|
||||
boss.ChangeState<SpiderChaseState>();
|
||||
return;
|
||||
}
|
||||
|
||||
// 全速力で直線移動
|
||||
boss.transform.position += chargeDirection * boss.chargeSpeed * Time.deltaTime;
|
||||
|
||||
// ─── フェーズ2:突進中(NavMeshAgentが自動で走っているので、スクリプト側はタイマーを監視するだけ) ───
|
||||
chargeTimer -= Time.deltaTime;
|
||||
if (chargeTimer <= 0f)
|
||||
|
||||
// 壁やプレイヤーに激突して完全に急停止したか、または設定時間が経過したら安全に終了
|
||||
if (chargeTimer <= 0f || boss.Agent.velocity.magnitude < 0.2f && chargeTimer < (boss.chargeDuration - 0.3f))
|
||||
{
|
||||
// 時間を駆け抜けたら追跡に戻る
|
||||
boss.ChangeState<SpiderChaseState>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// ■ STATE: JUMP TO CEILING (天井への大ジャンプ)
|
||||
// ==========================================
|
||||
public class SpiderJumpToCeilingState : ISpiderState
|
||||
{
|
||||
private BossController boss;
|
||||
@@ -258,9 +243,6 @@ public class SpiderJumpToCeilingState : ISpiderState
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// ■ STATE: CEILING ATTACK (必殺技:天井糸吐き)
|
||||
// ==========================================
|
||||
public class SpiderCeilingAttackState : ISpiderState
|
||||
{
|
||||
private BossController boss;
|
||||
|
||||
Reference in New Issue
Block a user