ノックバックアニメーション追加

This commit is contained in:
KawakamiKento
2026-06-02 12:35:45 +09:00
parent 1568a27840
commit 6aaaca800b
8 changed files with 293 additions and 44 deletions

View File

@@ -1,5 +1,30 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!1101 &-4617766861655133771
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: Hit
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 4274158951045771678}
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 &-4086410789753474205 --- !u!1101 &-4086410789753474205
AnimatorStateTransition: AnimatorStateTransition:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1
@@ -168,7 +193,7 @@ BlendTree:
m_Mirror: 0 m_Mirror: 0
- serializedVersion: 2 - serializedVersion: 2
m_Motion: {fileID: 3094330708855449807, guid: 2d87094962c8b48478651fa8fe1f7a5a, type: 3} m_Motion: {fileID: 3094330708855449807, guid: 2d87094962c8b48478651fa8fe1f7a5a, type: 3}
m_Threshold: 1.5 m_Threshold: 0.5
m_Position: {x: 0, y: 0} m_Position: {x: 0, y: 0}
m_TimeScale: 1 m_TimeScale: 1
m_CycleOffset: 0 m_CycleOffset: 0
@@ -176,7 +201,7 @@ BlendTree:
m_Mirror: 0 m_Mirror: 0
- serializedVersion: 2 - serializedVersion: 2
m_Motion: {fileID: 3094330708855449807, guid: 40786e67f3ceb094b9c00543f295cb5f, type: 3} m_Motion: {fileID: 3094330708855449807, guid: 40786e67f3ceb094b9c00543f295cb5f, type: 3}
m_Threshold: 3.5 m_Threshold: 1.5
m_Position: {x: 0, y: 0} m_Position: {x: 0, y: 0}
m_TimeScale: 1 m_TimeScale: 1
m_CycleOffset: 0 m_CycleOffset: 0
@@ -185,7 +210,7 @@ BlendTree:
m_BlendParameter: Speed m_BlendParameter: Speed
m_BlendParameterY: Speed m_BlendParameterY: Speed
m_MinThreshold: 0 m_MinThreshold: 0
m_MaxThreshold: 3.5 m_MaxThreshold: 1.5
m_UseAutomaticThresholds: 0 m_UseAutomaticThresholds: 0
m_NormalizedBlendValues: 0 m_NormalizedBlendValues: 0
m_BlendType: 0 m_BlendType: 0
@@ -216,6 +241,12 @@ AnimatorController:
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 9100000} m_Controller: {fileID: 9100000}
- m_Name: Hit
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
@@ -254,6 +285,33 @@ AnimatorStateTransition:
m_InterruptionSource: 0 m_InterruptionSource: 0
m_OrderedInterruption: 1 m_OrderedInterruption: 1
m_CanTransitionToSelf: 1 m_CanTransitionToSelf: 1
--- !u!1102 &4274158951045771678
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Hit
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: 5962909044224272594}
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: 33ead5f6ecd30db40bc9209ff361f049, type: 3}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1102 &5198712320388512128 --- !u!1102 &5198712320388512128
AnimatorState: AnimatorState:
serializedVersion: 6 serializedVersion: 6
@@ -281,6 +339,28 @@ AnimatorState:
m_MirrorParameter: m_MirrorParameter:
m_CycleOffsetParameter: m_CycleOffsetParameter:
m_TimeParameter: m_TimeParameter:
--- !u!1101 &5962909044224272594
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!1107 &6365640674471234328 --- !u!1107 &6365640674471234328
AnimatorStateMachine: AnimatorStateMachine:
serializedVersion: 6 serializedVersion: 6
@@ -302,8 +382,12 @@ AnimatorStateMachine:
- serializedVersion: 1 - serializedVersion: 1
m_State: {fileID: -512179905455080162} m_State: {fileID: -512179905455080162}
m_Position: {x: 300, y: 300, z: 0} m_Position: {x: 300, y: 300, z: 0}
- serializedVersion: 1
m_State: {fileID: 4274158951045771678}
m_Position: {x: 300, y: -100, z: 0}
m_ChildStateMachines: [] m_ChildStateMachines: []
m_AnyStateTransitions: [] m_AnyStateTransitions:
- {fileID: -4617766861655133771}
m_EntryTransitions: [] m_EntryTransitions: []
m_StateMachineTransitions: {} m_StateMachineTransitions: {}
m_StateMachineBehaviours: [] m_StateMachineBehaviours: []

View File

@@ -603,7 +603,7 @@ AudioSource:
m_Enabled: 1 m_Enabled: 1
serializedVersion: 4 serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0} OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 16fba6d30ed741d4a9fdd6e79ee2f3ac, type: 3} m_audioClip: {fileID: 0}
m_Resource: {fileID: 8300000, guid: 16fba6d30ed741d4a9fdd6e79ee2f3ac, type: 3} m_Resource: {fileID: 8300000, guid: 16fba6d30ed741d4a9fdd6e79ee2f3ac, type: 3}
m_PlayOnAwake: 0 m_PlayOnAwake: 0
m_Volume: 1 m_Volume: 1
@@ -1638,7 +1638,7 @@ AudioSource:
m_Enabled: 1 m_Enabled: 1
serializedVersion: 4 serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0} OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 16fba6d30ed741d4a9fdd6e79ee2f3ac, type: 3} m_audioClip: {fileID: 0}
m_Resource: {fileID: 8300000, guid: 16fba6d30ed741d4a9fdd6e79ee2f3ac, type: 3} m_Resource: {fileID: 8300000, guid: 16fba6d30ed741d4a9fdd6e79ee2f3ac, type: 3}
m_PlayOnAwake: 0 m_PlayOnAwake: 0
m_Volume: 1 m_Volume: 1

View File

@@ -363,7 +363,7 @@ MonoBehaviour:
m_ManualValue: 0 m_ManualValue: 0
--- !u!120 &2761784063978902504 --- !u!120 &2761784063978902504
LineRenderer: LineRenderer:
serializedVersion: 2 serializedVersion: 3
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
@@ -382,6 +382,8 @@ LineRenderer:
m_RayTracingAccelStructBuildFlagsOverride: 0 m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1 m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1 m_SmallMeshCulling: 1
m_ForceMeshLod: -1
m_MeshLodSelectionBias: 0
m_RenderingLayerMask: 1 m_RenderingLayerMask: 1
m_RendererPriority: 0 m_RendererPriority: 0
m_Materials: m_Materials:
@@ -403,9 +405,11 @@ LineRenderer:
m_AutoUVMaxDistance: 0.5 m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89 m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_GlobalIlluminationMeshLod: 0
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 0 m_SortingOrder: 0
m_MaskInteraction: 0
m_Positions: [] m_Positions: []
m_Parameters: m_Parameters:
serializedVersion: 3 serializedVersion: 3
@@ -471,7 +475,6 @@ LineRenderer:
textureScale: {x: 1, y: 1} textureScale: {x: 1, y: 1}
shadowBias: 0.5 shadowBias: 0.5
generateLightingData: 0 generateLightingData: 0
m_MaskInteraction: 0
m_UseWorldSpace: 1 m_UseWorldSpace: 1
m_Loop: 0 m_Loop: 0
m_ApplyActiveColorSpace: 0 m_ApplyActiveColorSpace: 0
@@ -637,6 +640,7 @@ SortingGroup:
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 30005 m_SortingOrder: 30005
m_SortAtRoot: 0 m_SortAtRoot: 0
m_Sort3DAs2D: 0
--- !u!114 &3616344554909481683 --- !u!114 &3616344554909481683
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -635,7 +635,6 @@ MonoBehaviour:
m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0} m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0}
m_RequiresDepthTexture: 0 m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0 m_RequiresColorTexture: 0
m_Version: 2
m_TaaSettings: m_TaaSettings:
m_Quality: 3 m_Quality: 3
m_FrameInfluence: 0.1 m_FrameInfluence: 0.1
@@ -643,6 +642,7 @@ MonoBehaviour:
m_MipBias: 0 m_MipBias: 0
m_VarianceClampScale: 0.9 m_VarianceClampScale: 0.9
m_ContrastAdaptiveSharpening: 0 m_ContrastAdaptiveSharpening: 0
m_Version: 2
--- !u!1 &58445280694286476 --- !u!1 &58445280694286476
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1978,6 +1978,10 @@ PrefabInstance:
propertyPath: m_Parameters.numCapVertices propertyPath: m_Parameters.numCapVertices
value: 4 value: 4
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2761784063978902504, guid: c1800acf6366418a9b5f610249000331, type: 3}
propertyPath: m_Parameters.widthMultiplier
value: 0.01
objectReference: {fileID: 0}
- target: {fileID: 2761784063978902504, guid: c1800acf6366418a9b5f610249000331, type: 3} - target: {fileID: 2761784063978902504, guid: c1800acf6366418a9b5f610249000331, type: 3}
propertyPath: m_Parameters.numCornerVertices propertyPath: m_Parameters.numCornerVertices
value: 4 value: 4
@@ -2225,6 +2229,10 @@ PrefabInstance:
propertyPath: m_Parameters.numCapVertices propertyPath: m_Parameters.numCapVertices
value: 4 value: 4
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2761784063978902504, guid: c1800acf6366418a9b5f610249000331, type: 3}
propertyPath: m_Parameters.widthMultiplier
value: 0.01
objectReference: {fileID: 0}
- target: {fileID: 2761784063978902504, guid: c1800acf6366418a9b5f610249000331, type: 3} - target: {fileID: 2761784063978902504, guid: c1800acf6366418a9b5f610249000331, type: 3}
propertyPath: m_Parameters.numCornerVertices propertyPath: m_Parameters.numCornerVertices
value: 4 value: 4

View File

@@ -3212,7 +3212,7 @@ GameObject:
- component: {fileID: 404289282} - component: {fileID: 404289282}
m_Layer: 0 m_Layer: 0
m_Name: Player m_Name: Player
m_TagString: Untagged m_TagString: Player
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
@@ -3281,8 +3281,8 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 404289281} m_GameObject: {fileID: 404289281}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0.0010081945, y: -0.51918787, z: -0.00063397904, w: -0.8546594}
m_LocalPosition: {x: 20, y: 26.062, z: -3.099} m_LocalPosition: {x: -39.541996, y: 25.250708, z: 11.4522085}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
@@ -3668,8 +3668,8 @@ Rigidbody:
m_Bits: 0 m_Bits: 0
m_ImplicitCom: 1 m_ImplicitCom: 1
m_ImplicitTensor: 1 m_ImplicitTensor: 1
m_UseGravity: 1 m_UseGravity: 0
m_IsKinematic: 0 m_IsKinematic: 1
m_Interpolate: 0 m_Interpolate: 0
m_Constraints: 112 m_Constraints: 112
m_CollisionDetection: 0 m_CollisionDetection: 0
@@ -3686,7 +3686,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: Assembly-CSharp::EnemyHealth m_EditorClassIdentifier: Assembly-CSharp::EnemyHealth
maxHealth: 100 maxHealth: 100
knockbackForce: 5 knockbackDuration: 0.5
--- !u!114 &438681048 --- !u!114 &438681048
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -3722,7 +3722,7 @@ NavMeshAgent:
m_Enabled: 1 m_Enabled: 1
m_AgentTypeID: 0 m_AgentTypeID: 0
m_Radius: 0.5 m_Radius: 0.5
m_Speed: 3.5 m_Speed: 2
m_Acceleration: 8 m_Acceleration: 8
avoidancePriority: 50 avoidancePriority: 50
m_AngularSpeed: 120 m_AngularSpeed: 120
@@ -14557,7 +14557,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: Assembly-CSharp::EnemyHealth m_EditorClassIdentifier: Assembly-CSharp::EnemyHealth
maxHealth: 100 maxHealth: 100
knockbackForce: 5 knockbackDuration: 0.5
--- !u!54 &657866389 --- !u!54 &657866389
Rigidbody: Rigidbody:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -15530,7 +15530,7 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3} - target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
value: -0.70598936 value: -0.9362131
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3} - target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
@@ -15538,11 +15538,11 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3} - target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: 0.7082225 value: -0.351433
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3} - target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: -0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3} - target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3}
propertyPath: m_LocalEulerAnglesHint.x propertyPath: m_LocalEulerAnglesHint.x
@@ -15550,7 +15550,7 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3} - target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3}
propertyPath: m_LocalEulerAnglesHint.y propertyPath: m_LocalEulerAnglesHint.y
value: 269.819 value: 401.15
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3} - target: {fileID: 8806329115733545878, guid: 77e7c27b2c5525e4aa8cc9f99d654486, type: 3}
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
@@ -651983,7 +651983,7 @@ PrefabInstance:
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: 2.33 value: 12.68
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

View File

@@ -1,6 +1,7 @@
using UnityEngine; using UnityEngine;
using UnityEngine.AI; using UnityEngine.AI;
using System.Collections; using System.Collections;
using System;
[RequireComponent(typeof(NavMeshAgent))] [RequireComponent(typeof(NavMeshAgent))]
[RequireComponent(typeof(Animator))] [RequireComponent(typeof(Animator))]
@@ -49,6 +50,8 @@ public class EnemyAI : MonoBehaviour
private bool isCooldown = false; private bool isCooldown = false;
private bool isAttacking = false; private bool isAttacking = false;
private bool isWandering = false; private bool isWandering = false;
private bool isKnockbacking = false;
private bool isDead = false;
private void Start() private void Start()
{ {
@@ -61,6 +64,8 @@ public class EnemyAI : MonoBehaviour
private void Update() private void Update()
{ {
if(isDead) return;
// 毎フレームのアニメーションパラメータ更新処理 // 毎フレームのアニメーションパラメータ更新処理
UpdateAnimation(); UpdateAnimation();
@@ -73,14 +78,16 @@ public class EnemyAI : MonoBehaviour
{ {
while (true) while (true)
{ {
if(isDead) yield break;
// プレイヤーが未検出の場合はタグから検索 // プレイヤーが未検出の場合はタグから検索
if (playerTransform == null) if (playerTransform == null)
{ {
FindPlayer(); FindPlayer();
} }
// 攻撃アニメーションの再生中でない場合のみ、ステートに応じた行動を実行 // 攻撃、のけぞりアニメーションの再生中でない場合のみ、ステートに応じた行動を実行
if (!isAttacking) if (!isAttacking && !isKnockbacking)
{ {
switch (currentState) switch (currentState)
{ {
@@ -164,9 +171,12 @@ public class EnemyAI : MonoBehaviour
return; return;
} }
// クールダウン中であっても、追跡ステートである限りはプレイヤーの現在位置を追い続け // のけぞり中でない場合、追跡の目的地を更新す
if(!isKnockbacking)
{
agent.SetDestination(playerTransform.position); agent.SetDestination(playerTransform.position);
} }
}
/// 【攻撃状態】の思考ロジック /// 【攻撃状態】の思考ロジック
private void AttackBehavior() private void AttackBehavior()
@@ -201,7 +211,7 @@ public class EnemyAI : MonoBehaviour
float targetSpeed = 0f; float targetSpeed = 0f;
// 攻撃中でなく、経路が存在し、かつ実際に一定以上の速度で移動している場合のみSpeedを1にする // 攻撃中でなく、経路が存在し、かつ実際に一定以上の速度で移動している場合のみSpeedを1にする
if (!isAttacking && agent.hasPath && agent.velocity.magnitude > 0.1f) if (!isAttacking && !isKnockbacking && agent.hasPath && agent.velocity.magnitude > 0.1f)
{ {
targetSpeed = 1f; targetSpeed = 1f;
} }
@@ -213,7 +223,7 @@ public class EnemyAI : MonoBehaviour
/// 攻撃ステートの際、プレイヤーの方向へ滑らかに旋回させる /// 攻撃ステートの際、プレイヤーの方向へ滑らかに旋回させる
private void UpdateRotationOnAttack() private void UpdateRotationOnAttack()
{ {
if (currentState == AIState.Attack && playerTransform != null) if (currentState == AIState.Attack && playerTransform != null && !isKnockbacking)
{ {
Vector3 direction = (playerTransform.position - transform.position).normalized; Vector3 direction = (playerTransform.position - transform.position).normalized;
direction.y = 0; // 上下方向の傾き(ピッチ回転)を無視 direction.y = 0; // 上下方向の傾き(ピッチ回転)を無視
@@ -227,6 +237,60 @@ public class EnemyAI : MonoBehaviour
} }
#endregion #endregion
// ダメージを受けた際に、EnemyhHealthから呼び出されるのけぞり開始メソッド
public void TriggerKnockback(float duration)
{
if(isDead) return;
StopAllCoroutines();
isAttacking = false;
isWandering = false;
isKnockbacking = false;
if(agent.isOnNavMesh)
{
agent.isStopped = false;
}
StartCoroutine(KnockbackRoutine(duration));
}
public void DisableAIOnDeath()
{
isDead = true;
StopAllCoroutines();
if(agent != null && agent.isOnNavMesh)
{
agent.isStopped = true;
agent.ResetPath();
}
}
private IEnumerator KnockbackRoutine(float duration)
{
isKnockbacking = true;
if(agent.isOnNavMesh)
{
agent.isStopped = true;
agent.ResetPath();
}
anim.SetTrigger("Hit");
yield return new WaitForSeconds(duration);
if(agent.isOnNavMesh)
{
agent.isStopped = false;
}
isKnockbacking = false;
isCooldown = false;
StartCoroutine(AILoop());
}
#region #region
/// 徘徊時のランダム移動を制御するコルーチン /// 徘徊時のランダム移動を制御するコルーチン
private IEnumerator WanderMoveRoutine() private IEnumerator WanderMoveRoutine()
@@ -274,7 +338,7 @@ public class EnemyAI : MonoBehaviour
} }
// 到着または諦めた後、ランダムな時間その場で待機 // 到着または諦めた後、ランダムな時間その場で待機
yield return new WaitForSeconds(Random.Range(minWaitTime, maxWaitTime)); yield return new WaitForSeconds(UnityEngine.Random.Range(minWaitTime, maxWaitTime));
isWandering = false; isWandering = false;
} }
@@ -289,6 +353,8 @@ public class EnemyAI : MonoBehaviour
yield return new WaitForSeconds(telegraphDuration); yield return new WaitForSeconds(telegraphDuration);
if(isKnockbacking) yield break;
anim.SetTrigger("Attack"); anim.SetTrigger("Attack");
} }
@@ -313,7 +379,7 @@ public class EnemyAI : MonoBehaviour
/// 攻撃アニメーションのヒットフレームで実行されるヒット判定Animation Eventから呼び出し /// 攻撃アニメーションのヒットフレームで実行されるヒット判定Animation Eventから呼び出し
public void OnPunchHit() public void OnPunchHit()
{ {
if (playerTransform == null) return; if (isKnockbacking || playerTransform == null) return;
float distanceToPlayer = Vector3.Distance(transform.position, playerTransform.position); float distanceToPlayer = Vector3.Distance(transform.position, playerTransform.position);
@@ -327,6 +393,7 @@ public class EnemyAI : MonoBehaviour
/// Recovery硬直アニメーションの終了時に実行される処理Animation Eventから呼び出し /// Recovery硬直アニメーションの終了時に実行される処理Animation Eventから呼び出し
public void OnRecoveryEnd() public void OnRecoveryEnd()
{ {
if(isKnockbacking) return;
isAttacking = false; isAttacking = false;
if (playerTransform == null) if (playerTransform == null)
@@ -358,7 +425,7 @@ public class EnemyAI : MonoBehaviour
/// 指定された中心座標の範囲内から、NavMesh上の有効なランダム座標を取得する /// 指定された中心座標の範囲内から、NavMesh上の有効なランダム座標を取得する
private Vector3 GetRandomNavMeshPoint(Vector3 center, float radius) private Vector3 GetRandomNavMeshPoint(Vector3 center, float radius)
{ {
Vector3 randomDirection = Random.insideUnitSphere * radius; Vector3 randomDirection = UnityEngine.Random.insideUnitSphere * radius;
randomDirection += center; randomDirection += center;
NavMeshHit hit; NavMeshHit hit;

View File

@@ -6,13 +6,13 @@ public class EnemyHealth : MonoBehaviour, IDamageble
[SerializeField] private float maxHealth = 100f; [SerializeField] private float maxHealth = 100f;
private float currentHealth; private float currentHealth;
[SerializeField] private float knockbackForce = 5f; [SerializeField] private float knockbackDuration = 0.5f;
private Rigidbody rb; private EnemyAI enemyAI;
void Start() void Start()
{ {
currentHealth = maxHealth; //HPを代入 currentHealth = maxHealth; //HPを代入
rb = GetComponent<Rigidbody>(); enemyAI = GetComponent<EnemyAI>();
} }
public void TakeDamage(DamageInfo damageInfo) public void TakeDamage(DamageInfo damageInfo)
@@ -26,19 +26,26 @@ public class EnemyHealth : MonoBehaviour, IDamageble
Debug.Log("構えボーナス"); Debug.Log("構えボーナス");
} }
if(rb != null) //ノックバック
{
rb.AddForce(damageInfo.punchDirection * knockbackForce, ForceMode.Impulse); //パンチが飛んできた方向に力を加える
}
if(currentHealth <= 0) if(currentHealth <= 0)
{ {
Die(); Die();
} }
else
{
if(enemyAI != null)
{
enemyAI.TriggerKnockback(knockbackDuration);
}
}
} }
private void Die() private void Die()
{ {
if(enemyAI != null)
{
enemyAI.DisableAIOnDeath();
}
Destroy(gameObject, 0.5f); Destroy(gameObject, 0.5f);
} }
} }

View File

@@ -482,6 +482,28 @@ MonoBehaviour:
targetOpenXRApiVersion: targetOpenXRApiVersion:
required: 0 required: 0
customRuntimeLoaderName: customRuntimeLoaderName:
--- !u!114 &-5208808512427716356
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 12d3bf61b014a48a2b7564c61da9d7ad, type: 3}
m_Name: AndroidXRPerformanceMetrics Standalone
m_EditorClassIdentifier: Unity.XR.AndroidOpenXR::UnityEngine.XR.OpenXR.Features.Android.AndroidXRPerformanceMetrics
m_enabled: 0
nameUi: Android XR Performance Metrics
version: 0.1.0
featureIdInternal: com.unity.openxr.feature.androidxr-performance-metrics
openxrExtensionStrings: XR_ANDROID_performance_metrics
company: Unity Technologies
priority: 0
targetOpenXRApiVersion:
required: 0
customRuntimeLoaderName:
--- !u!114 &-5020865716739387940 --- !u!114 &-5020865716739387940
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -521,8 +543,18 @@ MonoBehaviour:
features: features:
- {fileID: 8736661028334727731} - {fileID: 8736661028334727731}
- {fileID: 3598254934845347770} - {fileID: 3598254934845347770}
- {fileID: -5208808512427716356}
- {fileID: 5091991234558418143}
- {fileID: 1170704673688743257} - {fileID: 1170704673688743257}
- {fileID: -1187533949232362847}
- {fileID: -949347770443697596}
- {fileID: -1529727133502117446}
- {fileID: 5153017048313567732} - {fileID: 5153017048313567732}
- {fileID: 265326132771859475}
- {fileID: 2834828863856360103}
- {fileID: -2851827796942056979}
- {fileID: -8128959895479975907}
- {fileID: 1118878472687837173}
- {fileID: 6481653220666705815} - {fileID: 6481653220666705815}
- {fileID: 7393116930172532905} - {fileID: 7393116930172532905}
- {fileID: 744375598501864353} - {fileID: 744375598501864353}
@@ -1147,8 +1179,8 @@ MonoBehaviour:
features: features:
- {fileID: 7011443450567333355} - {fileID: 7011443450567333355}
- {fileID: -671281728444007487} - {fileID: -671281728444007487}
- {fileID: 6956056911768161135} - {fileID: -901939997048047619}
- {fileID: -6387251413244805544} - {fileID: -1734471456787174204}
- {fileID: 8980318060753866109} - {fileID: 8980318060753866109}
- {fileID: -6559185765804338520} - {fileID: -6559185765804338520}
- {fileID: -4756202077021157709} - {fileID: -4756202077021157709}
@@ -1159,7 +1191,7 @@ MonoBehaviour:
- {fileID: 348827886137839178} - {fileID: 348827886137839178}
- {fileID: -7499073031166464939} - {fileID: -7499073031166464939}
- {fileID: 7666556398442971420} - {fileID: 7666556398442971420}
- {fileID: -142859899272520151} - {fileID: -7343570946846779558}
- {fileID: 3985858319333531581} - {fileID: 3985858319333531581}
- {fileID: -6511185071715886993} - {fileID: -6511185071715886993}
- {fileID: -4363231183632145407} - {fileID: -4363231183632145407}
@@ -1505,6 +1537,28 @@ MonoBehaviour:
targetOpenXRApiVersion: targetOpenXRApiVersion:
required: 0 required: 0
customRuntimeLoaderName: customRuntimeLoaderName:
--- !u!114 &1118878472687837173
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6c36843bac48b29469f79baf3c98f9b6, type: 3}
m_Name: AndroidXRHandMeshData Standalone
m_EditorClassIdentifier: Unity.XR.AndroidOpenXR::UnityEngine.XR.OpenXR.Features.Android.AndroidXRHandMeshData
m_enabled: 0
nameUi: 'Android XR: Hand Mesh Data'
version: 0.1.0
featureIdInternal: com.unity.openxr.feature.androidxr-hand-mesh-data
openxrExtensionStrings: XR_ANDROID_hand_mesh
company: Unity Technologies
priority: 0
targetOpenXRApiVersion:
required: 0
customRuntimeLoaderName:
--- !u!114 &1170704673688743257 --- !u!114 &1170704673688743257
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1521,7 +1575,7 @@ MonoBehaviour:
nameUi: 'Android XR: AR Anchor' nameUi: 'Android XR: AR Anchor'
version: 0.1.0 version: 0.1.0
featureIdInternal: com.unity.openxr.feature.arfoundation-androidxr-anchor featureIdInternal: com.unity.openxr.feature.arfoundation-androidxr-anchor
openxrExtensionStrings: XR_ANDROID_trackables XR_ANDROID_device_anchor_persistence openxrExtensionStrings: XR_ANDROID_trackables
company: Unity Technologies company: Unity Technologies
priority: 0 priority: 0
targetOpenXRApiVersion: targetOpenXRApiVersion:
@@ -2001,6 +2055,31 @@ MonoBehaviour:
targetOpenXRApiVersion: targetOpenXRApiVersion:
required: 0 required: 0
customRuntimeLoaderName: customRuntimeLoaderName:
--- !u!114 &5091991234558418143
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 90ae1e8c3c7a542bba339faf2e771c5a, type: 3}
m_Name: AndroidXRSupportFeature Standalone
m_EditorClassIdentifier: Unity.XR.AndroidOpenXR::UnityEngine.XR.OpenXR.Features.Android.AndroidXRSupportFeature
m_enabled: 0
nameUi: Android XR Support
version: 1.0.0
featureIdInternal: com.unity.openxr.feature.androidxr-support
openxrExtensionStrings:
company: Unity Technologies
priority: 0
targetOpenXRApiVersion:
required: 0
customRuntimeLoaderName:
symmetricProjection: 0
optimizeBufferDiscards: 1
multiviewRenderRegionsOptimizationMode: 0
--- !u!114 &5153017048313567732 --- !u!114 &5153017048313567732
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -2443,7 +2522,7 @@ MonoBehaviour:
nameUi: 'Android XR: AR Anchor' nameUi: 'Android XR: AR Anchor'
version: 0.1.0 version: 0.1.0
featureIdInternal: com.unity.openxr.feature.arfoundation-androidxr-anchor featureIdInternal: com.unity.openxr.feature.arfoundation-androidxr-anchor
openxrExtensionStrings: XR_ANDROID_trackables XR_ANDROID_device_anchor_persistence openxrExtensionStrings: XR_ANDROID_trackables
company: Unity Technologies company: Unity Technologies
priority: 0 priority: 0
targetOpenXRApiVersion: targetOpenXRApiVersion: