スタン状態追加

This commit is contained in:
KawakamiKento
2026-06-03 16:35:15 +09:00
parent 6aaaca800b
commit 69f5891a14
7 changed files with 369 additions and 44 deletions

View File

@@ -1,5 +1,32 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!1102 &-9213843072455903201
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Stun
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: 551695996419535402}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 3094330708855449807, guid: 6bc3ab383df35674db1c49d5c09cf9f3, type: 3}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1101 &-4617766861655133771 --- !u!1101 &-4617766861655133771
AnimatorStateTransition: AnimatorStateTransition:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1
@@ -104,6 +131,31 @@ AnimatorState:
m_MirrorParameter: m_MirrorParameter:
m_CycleOffsetParameter: m_CycleOffsetParameter:
m_TimeParameter: m_TimeParameter:
--- !u!1101 &-2177191287041199040
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: Dead
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 3858776489725453322}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &-1087799933439154294 --- !u!1101 &-1087799933439154294
AnimatorStateTransition: AnimatorStateTransition:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1
@@ -247,6 +299,18 @@ AnimatorController:
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 9100000} m_Controller: {fileID: 9100000}
- m_Name: Dead
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: Stun
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_AnimatorLayers: m_AnimatorLayers:
- serializedVersion: 5 - serializedVersion: 5
m_Name: Base Layer m_Name: Base Layer
@@ -260,6 +324,28 @@ AnimatorController:
m_IKPass: 0 m_IKPass: 0
m_SyncedLayerAffectsTiming: 0 m_SyncedLayerAffectsTiming: 0
m_Controller: {fileID: 9100000} m_Controller: {fileID: 9100000}
--- !u!1101 &551695996419535402
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 5198712320388512128}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &2869564516383402369 --- !u!1101 &2869564516383402369
AnimatorStateTransition: AnimatorStateTransition:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1
@@ -285,6 +371,32 @@ AnimatorStateTransition:
m_InterruptionSource: 0 m_InterruptionSource: 0
m_OrderedInterruption: 1 m_OrderedInterruption: 1
m_CanTransitionToSelf: 1 m_CanTransitionToSelf: 1
--- !u!1102 &3858776489725453322
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Death
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 5957932628511814003, guid: b09be4f98e05fa7489d148a376fc0f1c, type: 3}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1102 &4274158951045771678 --- !u!1102 &4274158951045771678
AnimatorState: AnimatorState:
serializedVersion: 6 serializedVersion: 6
@@ -385,9 +497,17 @@ AnimatorStateMachine:
- serializedVersion: 1 - serializedVersion: 1
m_State: {fileID: 4274158951045771678} m_State: {fileID: 4274158951045771678}
m_Position: {x: 300, y: -100, z: 0} m_Position: {x: 300, y: -100, z: 0}
- serializedVersion: 1
m_State: {fileID: 3858776489725453322}
m_Position: {x: 300, y: -200, z: 0}
- serializedVersion: 1
m_State: {fileID: -9213843072455903201}
m_Position: {x: 300, y: -300, z: 0}
m_ChildStateMachines: [] m_ChildStateMachines: []
m_AnyStateTransitions: m_AnyStateTransitions:
- {fileID: -4617766861655133771} - {fileID: -4617766861655133771}
- {fileID: -2177191287041199040}
- {fileID: 8508030687789852846}
m_EntryTransitions: [] m_EntryTransitions: []
m_StateMachineTransitions: {} m_StateMachineTransitions: {}
m_StateMachineBehaviours: [] m_StateMachineBehaviours: []
@@ -396,3 +516,28 @@ AnimatorStateMachine:
m_ExitPosition: {x: 600, y: 100, z: 0} m_ExitPosition: {x: 600, y: 100, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0} m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: 5198712320388512128} m_DefaultState: {fileID: 5198712320388512128}
--- !u!1101 &8508030687789852846
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: Stun
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -9213843072455903201}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1

View File

@@ -3707,6 +3707,7 @@ MonoBehaviour:
attackDamage: 10 attackDamage: 10
attackCooldown: 2 attackCooldown: 2
telegraphDuration: 0.8 telegraphDuration: 0.8
rightHandCollider: {fileID: 1991158664}
comboInterval: 0.8 comboInterval: 0.8
wanderRadius: 8 wanderRadius: 8
minWaitTime: 2 minWaitTime: 2
@@ -17497,6 +17498,10 @@ MonoBehaviour:
damageMultiplier: 10 damageMultiplier: 10
hapticAmplitude: 0.5 hapticAmplitude: 0.5
hapticDuration: 0.1 hapticDuration: 0.1
minParrySpeed: 1
parryStunDuration: 3
parryHapticAmplitude: 0.9
parryHapticDuration: 0.25
--- !u!65 &938850979 --- !u!65 &938850979
BoxCollider: BoxCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -651973,33 +651978,57 @@ PrefabInstance:
serializedVersion: 3 serializedVersion: 3
m_TransformParent: {fileID: 0} m_TransformParent: {fileID: 0}
m_Modifications: m_Modifications:
- target: {fileID: 7357282918100144696, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalPosition.x
value: 0.0019
objectReference: {fileID: 0}
- target: {fileID: 7357282918100144696, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalPosition.y
value: -0.00478
objectReference: {fileID: 0}
- target: {fileID: 7357282918100144696, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalPosition.z
value: 0.00012
objectReference: {fileID: 0}
- target: {fileID: 7357282918100144728, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalPosition.x
value: 0.00794
objectReference: {fileID: 0}
- target: {fileID: 7357282918100144728, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalPosition.y
value: 0.00156
objectReference: {fileID: 0}
- target: {fileID: 7357282918100144728, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalPosition.z
value: 0.0004
objectReference: {fileID: 0}
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3} - target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: -38.33 value: -35.87
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3} - target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalPosition.y propertyPath: m_LocalPosition.y
value: 26.042007 value: 26
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3} - target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: 12.68 value: -1.29
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3} - target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
value: 1 value: -0.72334737
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3} - target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: 0 value: -0.024862813
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3} - target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: 0 value: 0.6896066
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3} - target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: 0 value: -0.024355074
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3} - target: {fileID: 7357282918100144838, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_LocalEulerAnglesHint.x propertyPath: m_LocalEulerAnglesHint.x
@@ -652013,6 +652042,14 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7357282918100569688, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_TagString
value: EnemyFist
objectReference: {fileID: 0}
- target: {fileID: 7357282918100569720, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_TagString
value: Untagged
objectReference: {fileID: 0}
- target: {fileID: 7357282918100569830, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3} - target: {fileID: 7357282918100569830, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
propertyPath: m_Name propertyPath: m_Name
value: Skin_1 value: Skin_1
@@ -652052,6 +652089,9 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 7357282918100569830, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3} - targetCorrespondingSourceObject: {fileID: 7357282918100569830, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
insertIndex: -1 insertIndex: -1
addedObject: {fileID: 438681048} addedObject: {fileID: 438681048}
- targetCorrespondingSourceObject: {fileID: 7357282918100569688, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
insertIndex: -1
addedObject: {fileID: 1991158664}
m_SourcePrefab: {fileID: 100100000, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
--- !u!114 &1927926602 --- !u!114 &1927926602
MonoBehaviour: MonoBehaviour:
@@ -652739,6 +652779,32 @@ MonoBehaviour:
m_ShadowLayerMask: 1 m_ShadowLayerMask: 1
m_RenderingLayers: 1 m_RenderingLayers: 1
m_ShadowRenderingLayers: 1 m_ShadowRenderingLayers: 1
--- !u!1 &1991158661 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 7357282918100569688, guid: 935264455f4b40f4ab5ea045bf9d7a3c, type: 3}
m_PrefabInstance: {fileID: 1924402715}
m_PrefabAsset: {fileID: 0}
--- !u!135 &1991158664
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1991158661}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Radius: 1
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &1997079592 --- !u!1 &1997079592
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -12,7 +12,8 @@ public class EnemyAI : MonoBehaviour
{ {
Wander, // 徘徊 Wander, // 徘徊
Chase, // 追跡 Chase, // 追跡
Attack // 攻撃 Attack, // 攻撃
Stun // 怯み
} }
[Header("現在の状態")] [Header("現在の状態")]
@@ -32,6 +33,7 @@ public class EnemyAI : MonoBehaviour
[SerializeField] private float attackCooldown = 2.0f; [SerializeField] private float attackCooldown = 2.0f;
[Tooltip("攻撃の予兆時間 (秒)")] [Tooltip("攻撃の予兆時間 (秒)")]
[SerializeField] private float telegraphDuration = 0.6f; [SerializeField] private float telegraphDuration = 0.6f;
[SerializeField] private Collider rightHandCollider;
[Header("ループ攻撃の調整")] [Header("ループ攻撃の調整")]
[Tooltip("連続攻撃の間に挟む最低限のインターバル (秒)")] [Tooltip("連続攻撃の間に挟む最低限のインターバル (秒)")]
@@ -58,6 +60,8 @@ public class EnemyAI : MonoBehaviour
agent = GetComponent<NavMeshAgent>(); agent = GetComponent<NavMeshAgent>();
anim = GetComponent<Animator>(); anim = GetComponent<Animator>();
SetFistCollider(false);
// AIのメインループコルーチンを開始 // AIのメインループコルーチンを開始
StartCoroutine(AILoop()); StartCoroutine(AILoop());
} }
@@ -87,7 +91,7 @@ public class EnemyAI : MonoBehaviour
} }
// 攻撃、のけぞりアニメーションの再生中でない場合のみ、ステートに応じた行動を実行 // 攻撃、のけぞりアニメーションの再生中でない場合のみ、ステートに応じた行動を実行
if (!isAttacking && !isKnockbacking) if (!isAttacking && !isKnockbacking && currentState != AIState.Stun)
{ {
switch (currentState) switch (currentState)
{ {
@@ -211,7 +215,7 @@ public class EnemyAI : MonoBehaviour
float targetSpeed = 0f; float targetSpeed = 0f;
// 攻撃中でなく、経路が存在し、かつ実際に一定以上の速度で移動している場合のみSpeedを1にする // 攻撃中でなく、経路が存在し、かつ実際に一定以上の速度で移動している場合のみSpeedを1にする
if (!isAttacking && !isKnockbacking && agent.hasPath && agent.velocity.magnitude > 0.1f) if (!isAttacking && !isKnockbacking && currentState != AIState.Stun && agent.hasPath && agent.velocity.magnitude > 0.1f)
{ {
targetSpeed = 1f; targetSpeed = 1f;
} }
@@ -223,7 +227,7 @@ public class EnemyAI : MonoBehaviour
/// 攻撃ステートの際、プレイヤーの方向へ滑らかに旋回させる /// 攻撃ステートの際、プレイヤーの方向へ滑らかに旋回させる
private void UpdateRotationOnAttack() private void UpdateRotationOnAttack()
{ {
if (currentState == AIState.Attack && playerTransform != null && !isKnockbacking) if (currentState == AIState.Attack && playerTransform != null && !isKnockbacking && currentState != AIState.Stun)
{ {
Vector3 direction = (playerTransform.position - transform.position).normalized; Vector3 direction = (playerTransform.position - transform.position).normalized;
direction.y = 0; // 上下方向の傾き(ピッチ回転)を無視 direction.y = 0; // 上下方向の傾き(ピッチ回転)を無視
@@ -242,6 +246,7 @@ public class EnemyAI : MonoBehaviour
{ {
if(isDead) return; if(isDead) return;
SetFistCollider(false);
StopAllCoroutines(); StopAllCoroutines();
isAttacking = false; isAttacking = false;
isWandering = false; isWandering = false;
@@ -255,6 +260,21 @@ public class EnemyAI : MonoBehaviour
StartCoroutine(KnockbackRoutine(duration)); StartCoroutine(KnockbackRoutine(duration));
} }
public void TriggerParryStun(float duration)
{
if(isDead) return;
Debug.Log($"{gameObject.name}: parry = true Stunnow");
SetFistCollider(false);
StopAllCoroutines();
isAttacking = false;
isWandering = false;
isKnockbacking = false;
StartCoroutine(ParryStunRoutine(duration));
}
public void DisableAIOnDeath() public void DisableAIOnDeath()
{ {
isDead = true; isDead = true;
@@ -266,6 +286,31 @@ public class EnemyAI : MonoBehaviour
} }
} }
private IEnumerator ParryStunRoutine(float duration)
{
currentState = AIState.Stun;
if(agent.isOnNavMesh)
{
agent.isStopped = true;
agent.ResetPath();
}
anim.SetTrigger("Stun");
yield return new WaitForSeconds(duration);
if(agent.isOnNavMesh)
{
agent.isStopped = false;
}
currentState = AIState.Chase;
isCooldown = false;
StartCoroutine(AILoop());
}
private IEnumerator KnockbackRoutine(float duration) private IEnumerator KnockbackRoutine(float duration)
{ {
isKnockbacking = true; isKnockbacking = true;
@@ -379,21 +424,17 @@ public class EnemyAI : MonoBehaviour
/// 攻撃アニメーションのヒットフレームで実行されるヒット判定Animation Eventから呼び出し /// 攻撃アニメーションのヒットフレームで実行されるヒット判定Animation Eventから呼び出し
public void OnPunchHit() public void OnPunchHit()
{ {
if (isKnockbacking || playerTransform == null) return; if (isKnockbacking || currentState == AIState.Stun) return;
float distanceToPlayer = Vector3.Distance(transform.position, playerTransform.position); SetFistCollider(true);
// ヒット判定の瞬間、プレイヤーが射程内に残っているか判定猶予として0.3m加算)
if (distanceToPlayer <= attackRange + 0.3f)
{
Debug.Log($"💥 敵のパンチがヒット!");
}
} }
/// Recovery硬直アニメーションの終了時に実行される処理Animation Eventから呼び出し /// Recovery硬直アニメーションの終了時に実行される処理Animation Eventから呼び出し
public void OnRecoveryEnd() public void OnRecoveryEnd()
{ {
if(isKnockbacking) return; if(isKnockbacking || currentState == AIState.Stun) return;
SetFistCollider(false);
isAttacking = false; isAttacking = false;
if (playerTransform == null) if (playerTransform == null)
@@ -423,6 +464,14 @@ public class EnemyAI : MonoBehaviour
#region #region
/// 指定された中心座標の範囲内から、NavMesh上の有効なランダム座標を取得する /// 指定された中心座標の範囲内から、NavMesh上の有効なランダム座標を取得する
private void SetFistCollider(bool enabledState)
{
if(rightHandCollider != null)
{
rightHandCollider.enabled = enabledState;
}
}
private Vector3 GetRandomNavMeshPoint(Vector3 center, float radius) private Vector3 GetRandomNavMeshPoint(Vector3 center, float radius)
{ {
Vector3 randomDirection = UnityEngine.Random.insideUnitSphere * radius; Vector3 randomDirection = UnityEngine.Random.insideUnitSphere * radius;

View File

@@ -9,6 +9,8 @@ public class EnemyHealth : MonoBehaviour, IDamageble
[SerializeField] private float knockbackDuration = 0.5f; [SerializeField] private float knockbackDuration = 0.5f;
private EnemyAI enemyAI; private EnemyAI enemyAI;
private bool isDead = false;
void Start() void Start()
{ {
currentHealth = maxHealth; //HPを代入 currentHealth = maxHealth; //HPを代入
@@ -41,11 +43,26 @@ public class EnemyHealth : MonoBehaviour, IDamageble
private void Die() private void Die()
{ {
if(isDead) return;
isDead = true;
Animator anim = GetComponent<Animator>();
if(anim != null)
{
anim.SetTrigger("Dead");
}
Collider col = GetComponent<Collider>();
if(col != null)
{
col.enabled = false;
}
if(enemyAI != null) if(enemyAI != null)
{ {
enemyAI.DisableAIOnDeath(); enemyAI.DisableAIOnDeath();
} }
Destroy(gameObject, 0.5f); Destroy(gameObject, 3.0f);
} }
} }

View File

@@ -7,17 +7,25 @@ using UnityEngine.XR; // 振動機能のために必要
public class VRInputPunch : MonoBehaviour public class VRInputPunch : MonoBehaviour
{ {
[SerializeField] private InputActionProperty velocityAction; [SerializeField] private InputActionProperty velocityAction;
[SerializeField] private XRNode controllerNode = XRNode.RightHand; [SerializeField] private XRNode controllerNode = XRNode.RightHand;
[SerializeField] private VRInputPoseDetector poseDetector; [SerializeField] private VRInputPoseDetector poseDetector;
[Header("攻撃(パンチ)設定")]
[SerializeField] private float minPunchSpeed = 2.0f; // パンチとして判定する最低速度 (m/s) [SerializeField] private float minPunchSpeed = 2.0f; // パンチとして判定する最低速度 (m/s)
[SerializeField] private float damageMultiplier = 10.0f; // ダメージ倍率 [SerializeField] private float damageMultiplier = 10.0f; // ダメージ倍率
[SerializeField] private float hapticAmplitude = 0.5f; // 通常ヒットの振動の強さ
[SerializeField] private float hapticDuration = 0.1f; // 通常ヒットの振動の長さ
[SerializeField] private float hapticAmplitude = 0.5f; //振動の強さ [Header("パリィ設定")]
[SerializeField] private float hapticDuration = 0.1f; //振動の長さ [Tooltip("パリィを成立させるために必要な最低限の手の速度 (m/s) ※構え中は速度に関係なく成功します")]
[SerializeField] private float minParrySpeed = 1.0f;
[Tooltip("パリィ成功時に敵がスタン(行動不能)になる時間 (秒)")]
[SerializeField] private float parryStunDuration = 3.0f;
[Tooltip("パリィ成功時の強力な振動の強さ (0.0 1.0)")]
[SerializeField] private float parryHapticAmplitude = 0.9f;
[Tooltip("パリィ成功時の強力な振動の長さ (秒)")]
[SerializeField] private float parryHapticDuration = 0.25f;
// ─────────────────────────────────────────
private void OnEnable() private void OnEnable()
{ {
@@ -45,10 +53,42 @@ public class VRInputPunch : MonoBehaviour
private void OnTriggerEnter(Collider other) private void OnTriggerEnter(Collider other)
{ {
// コントローラーの現在の移動速度を取得
Vector3 velocity = velocityAction.action.ReadValue<Vector3>(); Vector3 velocity = velocityAction.action.ReadValue<Vector3>();
float speed = velocity.magnitude; float speed = velocity.magnitude;
// ─── ★新設:【パリィ判定】当たったオブジェクトが「敵の拳」だった場合 ───
if (other.CompareTag("EnemyFist"))
{
Debug.Log($"🛡️ [パリィチェック] 敵の拳と接触。プレイヤーの手の速度: {speed:F2} m/s / 構え状態: {poseDetector.IsPosing}");
// 条件構え状態IsPosingである、もしくは、弾くための速度が一定以上出ている場合
if (poseDetector.IsPosing || speed >= minParrySpeed)
{
// 敵の親オブジェクトからEnemyAIスクリプトを検索
EnemyAI enemyAI = other.GetComponentInParent<EnemyAI>();
if (enemyAI != null)
{
// 敵の攻撃コンボを強制中断し、スタン状態にする
enemyAI.TriggerParryStun(parryStunDuration);
// パリィ成功用の強力な振動(手応え)をプレイヤーに返す
TriggerHaptics(parryHapticAmplitude, parryHapticDuration);
Debug.Log($"🛡️ 【ジャストパリィ成功!】 敵の体勢を崩しました。スタン時間: {parryStunDuration}秒");
return; // パリィが成立した場合は以降のパンチ処理は行わない
}
}
else
{
Debug.Log("🧱 ガード(または速度不足):敵の攻撃は防いだが、弾き返せなかった。");
return;
}
}
// ────────────────────────────────────────────────────────────────────────
// ─── 以下は従来の【パンチ攻撃】の処理(変更なし・ログのバグ修正のみ) ───
Debug.Log($"[InputSystem接触] {other.name} に触れました。センサー速度: {speed:F2} m/s"); Debug.Log($"[InputSystem接触] {other.name} に触れました。センサー速度: {speed:F2} m/s");
if (speed >= minPunchSpeed) if (speed >= minPunchSpeed)
@@ -69,26 +109,33 @@ public class VRInputPunch : MonoBehaviour
info.isPoseBonus = false; info.isPoseBonus = false;
} }
info.hitPosition = other.transform.position; info.hitPosition = other.transform.position;
info.punchDirection = velocity.normalized; //パンチの進む向き info.punchDirection = velocity.normalized;
damageble.TakeDamage(info);
Debug.Log("パンチ成功 ダメージ: {damage:F1}");
TriggerHaptics(); damageble.TakeDamage(info);
// ※元のコードのログ出力の記述バグ($の付け忘れ)を修正しました
Debug.Log($"パンチ成功 ダメージ: {info.amount:F1}");
// 通常ヒットの振動を発生
TriggerHaptics(hapticAmplitude, hapticDuration);
}
} }
else else
{ {
Debug.Log("スピードが足りません。必要: {minPunchSpeed} / 現在: {speed:F2}"); // ※元のコードのログ出力の記述バグ($の付け忘れ)を修正しました
} Debug.Log($"スピードが足りません。必要: {minPunchSpeed} / 現在: {speed:F2}");
} }
} }
// コントローラーを振動させる処理 /// <summary>
private void TriggerHaptics() /// 引数に応じて指定された強さと長さでコントローラーを振動させる
/// </summary>
private void TriggerHaptics(float amplitude, float duration)
{ {
UnityEngine.XR.InputDevice device = InputDevices.GetDeviceAtXRNode(controllerNode); UnityEngine.XR.InputDevice device = InputDevices.GetDeviceAtXRNode(controllerNode);
if (device.isValid) if (device.isValid)
{ {
device.SendHapticImpulse(0, hapticAmplitude, hapticDuration); device.SendHapticImpulse(0, amplitude, duration);
} }
} }
} }

View File

@@ -1179,8 +1179,8 @@ MonoBehaviour:
features: features:
- {fileID: 7011443450567333355} - {fileID: 7011443450567333355}
- {fileID: -671281728444007487} - {fileID: -671281728444007487}
- {fileID: -901939997048047619} - {fileID: 6956056911768161135}
- {fileID: -1734471456787174204} - {fileID: -6387251413244805544}
- {fileID: 8980318060753866109} - {fileID: 8980318060753866109}
- {fileID: -6559185765804338520} - {fileID: -6559185765804338520}
- {fileID: -4756202077021157709} - {fileID: -4756202077021157709}
@@ -1191,7 +1191,7 @@ MonoBehaviour:
- {fileID: 348827886137839178} - {fileID: 348827886137839178}
- {fileID: -7499073031166464939} - {fileID: -7499073031166464939}
- {fileID: 7666556398442971420} - {fileID: 7666556398442971420}
- {fileID: -7343570946846779558} - {fileID: -142859899272520151}
- {fileID: 3985858319333531581} - {fileID: 3985858319333531581}
- {fileID: -6511185071715886993} - {fileID: -6511185071715886993}
- {fileID: -4363231183632145407} - {fileID: -4363231183632145407}

View File

@@ -6,6 +6,7 @@ TagManager:
tags: tags:
- Anchor - Anchor
- Enemy - Enemy
- EnemyFist
layers: layers:
- Default - Default
- TransparentFX - TransparentFX