anim is gooder

This commit is contained in:
ohgushiyuga
2026-07-07 16:06:00 +09:00
parent bb90c969b4
commit b8c7e6edd8
6 changed files with 1579 additions and 497 deletions

View File

@@ -11,7 +11,7 @@ public class BossController : MonoBehaviour
[SerializeField] private float maxHp = 500f;
[SerializeField] private float currentHp = 500f;
[SerializeField] public float chaseRange = 15f;
[SerializeField] public float biteRange = 8f;
[SerializeField] public float biteRange = 5f;
[Header("必殺技(天井)設定")]
[Tooltip("天井の待機座標となる空のGameObjectのTransformを指定してください")]
@@ -197,6 +197,21 @@ public class BossController : MonoBehaviour
Destroy(web, duration); // 数秒後に自動消滅
}
}
/// <summary>
/// ★超重要:アニメーターに残ってしまった不要なトリガーをすべて強制消去(リセット)する
/// これを各ステートのExit時に呼ぶことで、アニメーションが固まる・遅れて暴発するバグを根絶します
/// </summary>
public void ResetAllAnimationTriggers()
{
if (Anim == null) return;
Anim.ResetTrigger("Attack_Bite");
Anim.ResetTrigger("Attack_Roar");
Anim.ResetTrigger("ChargeStart");
Anim.ResetTrigger("JumpUp");
Anim.ResetTrigger("Land");
Anim.ResetTrigger("StunStart");
}
#endregion
}

View File

@@ -27,7 +27,11 @@ public class SpiderChaseState : ISpiderState
public SpiderChaseState(BossController owner) => boss = owner;
public void EnterState() => boss.Agent.isStopped = false;
public void ExitState() => boss.Agent.isStopped = true;
public void ExitState()
{
boss.Agent.isStopped = true;
boss.ResetAllAnimationTriggers();
}
public void UpdateState()
{
@@ -55,7 +59,7 @@ public class SpiderChaseState : ISpiderState
}
// ==========================================
// ■ STATE: BITE (完全足止め・めり込み防止版)
// ■ STATE: BITE (完全静止・滑り移動ゼロ修正版)
// ==========================================
public class SpiderBiteState : ISpiderState
{
@@ -66,24 +70,34 @@ public class SpiderBiteState : ISpiderState
public void EnterState()
{
stateTimer = 1.5f;
stateTimer = 1.5f; // 噛みつきアニメーションの時間(環境に合わせて調整してください)
// ★超重要:噛みつきモーションに入った瞬間、移動を「完全強制停止」してめり込みを防ぐ
// 1. 【物理ブレーキ】これまでの移動経路を完全に忘却させ、慣性速度も強制ゼロにする
boss.Agent.ResetPath();
boss.Agent.isStopped = true;
boss.Agent.velocity = Vector3.zero; // 慣性もゼロにする
boss.Agent.velocity = Vector3.zero;
// 2. 【アニメーションブレーキ】直前の走っていた速度Speedを強制的に0リセット
// これをしないと、速度の減衰が遅れて「歩きながら噛み付く」ブレンドモーションになります
boss.Anim.SetFloat("Speed", 0f);
// 3. 噛みつきモーションを発動
boss.Anim.SetTrigger("Attack_Bite");
Debug.Log("🎯 蜘蛛ボス:噛みつき攻撃!(その場に完全固定)");
Debug.Log("🎯 蜘蛛ボス:噛みつき攻撃! 経路を完全消去してその場に固定しました。");
}
public void ExitState()
{
// ステートを出るときに停止ロックを解除する
// 次のステートChaseなどに安全に移行できるよう、ナビゲーションの停止を解除
boss.Agent.isStopped = false;
boss.ResetAllAnimationTriggers();
}
public void UpdateState()
{
// 4. 【徹底防衛】アニメーションの再生中に予期せぬ物理反発や滑りが発生しないよう、毎フレーム速度をゼロに固定
boss.Agent.velocity = Vector3.zero;
stateTimer -= Time.deltaTime;
if (stateTimer <= 0f)
{
@@ -93,6 +107,9 @@ public class SpiderBiteState : ISpiderState
}
}
// ==========================================
// ■ STATE: CHARGE (慣性ブレーキ完全修正版)
// ==========================================
public class SpiderChargeState : ISpiderState
{
private BossController boss;
@@ -105,26 +122,29 @@ public class SpiderChargeState : ISpiderState
public void EnterState()
{
roarTimer = 1.5f; // 溜め(咆哮)時間
roarTimer = 5f; // 溜め(咆哮)時間
chargeTimer = boss.chargeDuration;
isChargingPhase = false;
// ★重要:突進の溜め中は、NavMeshAgentの自動移動を「一時停止」にしてその場に固定する
// ★重要:ナビゲーションを止め、さらに残っている移動速度(慣性)を完全にゼロリセットする
boss.Agent.isStopped = true;
boss.Agent.velocity = Vector3.zero; // これにより滑り込みを100%防止します
boss.ResetChargeCooldown();
// その場に完全静止した状態で、満を持して咆哮アニメーションを再生
boss.Anim.SetTrigger("Attack_Roar");
Debug.Log("🔊 蜘蛛ボス:その場で突進の溜め(咆哮)開始");
Debug.Log("🔊 蜘蛛ボス:遠距離を検知してその場でピタッと完全停止。咆哮(溜め)を開始");
}
public void ExitState()
{
boss.Anim.SetBool("IsCharging", false);
// ★重要:突進ステートを出るときは、スピードと加速を通常のザコ敵・巡回時の値に必ず戻す
boss.Agent.speed = boss.NormalSpeed;
boss.Agent.acceleration = boss.NormalAcceleration;
boss.Agent.isStopped = false;
boss.ResetAllAnimationTriggers();
}
public void UpdateState()
@@ -134,6 +154,9 @@ public class SpiderChargeState : ISpiderState
{
roarTimer -= Time.deltaTime;
// ★安全対策溜め期間中、予期せぬ物理の反発などで1ミリも動かないように速度をゼロに固定し続ける
boss.Agent.velocity = Vector3.zero;
if (boss.Player != null)
{
Vector3 lookDir = (boss.Player.position - boss.transform.position).normalized;
@@ -151,34 +174,31 @@ public class SpiderChargeState : ISpiderState
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;
}
// 2. ★プロの技:ボスの正面方向の「遥か彼方(例: 20m先」に、突進の目的地座標を計算
// 20m先の目的地に向かって、NavMeshAgentによる超高速突進ダッシュを発射
Vector3 targetDestination = boss.transform.position + chargeDirection * 20f;
// 3. ★移動をNavMeshAgentに一任する超高速化
boss.Agent.isStopped = false; // 移動再開
boss.Agent.speed = boss.chargeSpeed; // スピードを全速力14fなど
boss.Agent.acceleration = 120f; // 即座に最高速に達するように加速を爆上げする
boss.Agent.isStopped = false;
boss.Agent.speed = boss.chargeSpeed;
boss.Agent.acceleration = 120f;
// 目的地を設定NavMeshの壁やプレイヤーのCharacterControllerを考慮して自動で進むようになる
boss.Agent.SetDestination(targetDestination);
Debug.Log("🚀 蜘蛛ボス:NavMesh突進ダッシュ発射!");
Debug.Log("🚀 蜘蛛ボス:ロックオン完了。全速力で突進ダッシュ発射!");
}
return;
}
// ─── フェーズ2突進中NavMeshAgentが自動で走っているので、スクリプト側はタイマーを監視するだけ ───
// ─── フェーズ2突進中 ───
chargeTimer -= Time.deltaTime;
// 壁やプレイヤーに激突して完全に急停止したか、または設定時間が経過したら安全に終了
if (chargeTimer <= 0f || boss.Agent.velocity.magnitude < 0.2f && chargeTimer < (boss.chargeDuration - 0.3f))
// 壁やプレイヤーに激突して急停止したか、設定時間が経過したら通常状態へ戻る
if (chargeTimer <= 0f || (boss.Agent.velocity.magnitude < 0.2f && chargeTimer < (boss.chargeDuration - 0.3f)))
{
boss.ChangeState<SpiderChaseState>();
}