From 6883df0d14554b4431d68b0fcffc192ddadc723f Mon Sep 17 00:00:00 2001 From: Nico Date: Tue, 15 Jul 2025 01:43:35 -0700 Subject: [PATCH] Added knockback control --- .../Animations/Player/AttackAnimation.controller | 16 ++++++++-------- Assets/Art/Animations/Player/Slash1.anim | 9 ++++++--- Assets/Art/Animations/Player/Slash2.anim | 9 ++++++--- Assets/Scenes/HomeTown.unity | 6 +++--- Assets/Scripts/Runtime/AI/EnemyManager/Gobler.cs | 6 ++++-- .../Characters/Player/Classes/ClassBase.cs | 4 +++- .../Player/Classes/MeleeFighterClass.cs | 6 +++--- .../Characters/Player/PlayerMainController.cs | 2 +- 8 files changed, 34 insertions(+), 24 deletions(-) diff --git a/Assets/Art/Animations/Player/AttackAnimation.controller b/Assets/Art/Animations/Player/AttackAnimation.controller index dfc4a8f..65c700c 100644 --- a/Assets/Art/Animations/Player/AttackAnimation.controller +++ b/Assets/Art/Animations/Player/AttackAnimation.controller @@ -40,11 +40,11 @@ AnimatorStateTransition: m_Mute: 0 m_IsExit: 0 serializedVersion: 3 - m_TransitionDuration: 0.25 + m_TransitionDuration: 0 m_TransitionOffset: 0 m_ExitTime: 0 m_HasExitTime: 1 - m_HasFixedDuration: 1 + m_HasFixedDuration: 0 m_InterruptionSource: 0 m_OrderedInterruption: 1 m_CanTransitionToSelf: 1 @@ -124,11 +124,11 @@ AnimatorStateTransition: m_Mute: 0 m_IsExit: 0 serializedVersion: 3 - m_TransitionDuration: 0.25 + m_TransitionDuration: -0 m_TransitionOffset: 0 m_ExitTime: 0 m_HasExitTime: 1 - m_HasFixedDuration: 1 + m_HasFixedDuration: 0 m_InterruptionSource: 0 m_OrderedInterruption: 1 m_CanTransitionToSelf: 1 @@ -167,8 +167,8 @@ AnimatorState: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: Slash2 - m_Speed: 0.5 + m_Name: Slash1 + m_Speed: 0.3 m_CycleOffset: 0 m_Transitions: - {fileID: 1744850431499835666} @@ -235,8 +235,8 @@ AnimatorState: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: Slash1 - m_Speed: 0.5 + m_Name: Slash2 + m_Speed: 0.3 m_CycleOffset: 0 m_Transitions: - {fileID: -7287591005394286135} diff --git a/Assets/Art/Animations/Player/Slash1.anim b/Assets/Art/Animations/Player/Slash1.anim index f4851e1..3299cf2 100644 --- a/Assets/Art/Animations/Player/Slash1.anim +++ b/Assets/Art/Animations/Player/Slash1.anim @@ -23,10 +23,12 @@ AnimationClip: - time: 0 value: {fileID: 2084452910934024698, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} - time: 0.016666668 - value: {fileID: -2736451627376223018, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} + value: {fileID: 2084452910934024698, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} - time: 0.033333335 - value: {fileID: -893459440294663468, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} + value: {fileID: -2736451627376223018, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} - time: 0.05 + value: {fileID: -893459440294663468, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} + - time: 0.06666667 value: {fileID: 5053079929507107595, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} attribute: m_Sprite path: @@ -51,6 +53,7 @@ AnimationClip: isSerializeReferenceCurve: 0 pptrCurveMapping: - {fileID: 2084452910934024698, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} + - {fileID: 2084452910934024698, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} - {fileID: -2736451627376223018, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} - {fileID: -893459440294663468, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} - {fileID: 5053079929507107595, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} @@ -59,7 +62,7 @@ AnimationClip: m_AdditiveReferencePoseClip: {fileID: 0} m_AdditiveReferencePoseTime: 0 m_StartTime: 0 - m_StopTime: 0.06666667 + m_StopTime: 0.083333336 m_OrientationOffsetY: 0 m_Level: 0 m_CycleOffset: 0 diff --git a/Assets/Art/Animations/Player/Slash2.anim b/Assets/Art/Animations/Player/Slash2.anim index 96fcb92..b9784e5 100644 --- a/Assets/Art/Animations/Player/Slash2.anim +++ b/Assets/Art/Animations/Player/Slash2.anim @@ -55,10 +55,12 @@ AnimationClip: - time: 0 value: {fileID: 2084452910934024698, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} - time: 0.016666668 - value: {fileID: -2736451627376223018, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} + value: {fileID: 2084452910934024698, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} - time: 0.033333335 - value: {fileID: -893459440294663468, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} + value: {fileID: -2736451627376223018, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} - time: 0.05 + value: {fileID: -893459440294663468, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} + - time: 0.06666667 value: {fileID: 5053079929507107595, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} attribute: m_Sprite path: @@ -101,6 +103,7 @@ AnimationClip: isSerializeReferenceCurve: 0 pptrCurveMapping: - {fileID: 2084452910934024698, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} + - {fileID: 2084452910934024698, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} - {fileID: -2736451627376223018, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} - {fileID: -893459440294663468, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} - {fileID: 5053079929507107595, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} @@ -109,7 +112,7 @@ AnimationClip: m_AdditiveReferencePoseClip: {fileID: 0} m_AdditiveReferencePoseTime: 0 m_StartTime: 0 - m_StopTime: 0.06666667 + m_StopTime: 0.083333336 m_OrientationOffsetY: 0 m_Level: 0 m_CycleOffset: 0 diff --git a/Assets/Scenes/HomeTown.unity b/Assets/Scenes/HomeTown.unity index 07b6370..b9741f3 100644 --- a/Assets/Scenes/HomeTown.unity +++ b/Assets/Scenes/HomeTown.unity @@ -86315,15 +86315,15 @@ SpriteRenderer: m_SortingLayerID: 651355007 m_SortingLayer: 4 m_SortingOrder: 0 - m_Sprite: {fileID: 2084452910934024698, guid: 309d09cd04eabea43bdf7c83eace0ecd, type: 3} + m_Sprite: {fileID: 0} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 - m_Size: {x: 1.25, y: 1.22} + m_Size: {x: 7.8125, y: 7.625} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 - m_WasSpriteAssigned: 1 + m_WasSpriteAssigned: 0 m_MaskInteraction: 0 m_SpriteSortPoint: 0 --- !u!95 &1868591329 diff --git a/Assets/Scripts/Runtime/AI/EnemyManager/Gobler.cs b/Assets/Scripts/Runtime/AI/EnemyManager/Gobler.cs index 93a77a0..25548ea 100644 --- a/Assets/Scripts/Runtime/AI/EnemyManager/Gobler.cs +++ b/Assets/Scripts/Runtime/AI/EnemyManager/Gobler.cs @@ -128,7 +128,7 @@ public class Gobler : Alive { case State.TakeDamage: - Rigidbody.linearVelocity = DirectionOfDamage * 100 * InvincibilityLeft; + Rigidbody.linearVelocity = DirectionOfDamage * Knockback * 10 * InvincibilityLeft; Materials.ForEach(x => x.SetFloat("_FlashAmount", InvincibilityLeft)); if (!IsInvincible) SetState(State.None); break; @@ -235,14 +235,16 @@ public class Alive { protected int DamageTaken; protected Vector2 DirectionOfDamage; + protected int Knockback; - public void TakeDamage(int amount, Vector2 hitDirection) { + public void Damage(int amount, Vector2 hitDirection, int knockback = 1) { if (IsDead || IsInvincible) return; CurrentHealth -= amount; CurrentHealth = Mathf.Max(CurrentHealth, 0); InvincibleUntil = Time.time + InvincibilityDuration; DamageTaken = amount; + Knockback = knockback; hitDirection = hitDirection.normalized; if (hitDirection == Vector2.zero) hitDirection = Vector2.up; diff --git a/Assets/Scripts/Runtime/Characters/Player/Classes/ClassBase.cs b/Assets/Scripts/Runtime/Characters/Player/Classes/ClassBase.cs index daaf52c..675aa9a 100644 --- a/Assets/Scripts/Runtime/Characters/Player/Classes/ClassBase.cs +++ b/Assets/Scripts/Runtime/Characters/Player/Classes/ClassBase.cs @@ -98,11 +98,12 @@ public class ClassBase { protected Coroutine AttackCoroutine; - protected void CreateHitBoxOffset(float centerOffset, float radius, float hitDelay, float hitDuration) { + protected void CreateHitBoxOffset(float centerOffset, float radius, float hitDelay, float hitDuration, int knockback) { if (AttackCoroutine != null) Player.Instance.StopCoroutine(AttackCoroutine); var center = PlayerPos + Player.PrevDirection * centerOffset; hitDelay = 0; + HitBoxDraw.Knockback = knockback; AttackCoroutine = Player.Instance.StartCoroutine(CreateHitBoxHelper(center, radius, hitDelay, hitDuration)); } @@ -130,5 +131,6 @@ public class ClassBase { public Vector2 Center; public float Radius; public Color Color; + public int Knockback; } } diff --git a/Assets/Scripts/Runtime/Characters/Player/Classes/MeleeFighterClass.cs b/Assets/Scripts/Runtime/Characters/Player/Classes/MeleeFighterClass.cs index fac7ca1..99ba36f 100644 --- a/Assets/Scripts/Runtime/Characters/Player/Classes/MeleeFighterClass.cs +++ b/Assets/Scripts/Runtime/Characters/Player/Classes/MeleeFighterClass.cs @@ -232,17 +232,17 @@ public class MeleeFighterClass : ClassBase { case AttackState.BasicAttack1: AnimationToPlay = "Attack1"; - CreateHitBoxOffset(4, 4, 0.1f, 0.1f); + CreateHitBoxOffset(4, 4, 0.1f, 0.1f, 10); break; case AttackState.BasicAttack2: AnimationToPlay = "Attack2"; - CreateHitBoxOffset(4, 4, 0.1f, 0.1f); + CreateHitBoxOffset(4, 4, 0.1f, 0.1f, 15); break; case AttackState.BasicAttack3: AnimationToPlay = "Attack1"; - CreateHitBoxOffset(4, 4, 0.1f, 0.1f); + CreateHitBoxOffset(4, 4, 0.1f, 0.1f, 20); break; case AttackState.KineticSurgeRelease: diff --git a/Assets/Scripts/Runtime/Characters/Player/PlayerMainController.cs b/Assets/Scripts/Runtime/Characters/Player/PlayerMainController.cs index 13d1320..149cfb6 100644 --- a/Assets/Scripts/Runtime/Characters/Player/PlayerMainController.cs +++ b/Assets/Scripts/Runtime/Characters/Player/PlayerMainController.cs @@ -204,7 +204,7 @@ public class Player : MonoBehaviour { GameObject parent = hit.transform.parent?.gameObject; //EnemySpawnerData.EnemyMap[parent].TakeDamage(0, transform.position - parent.transform.position); - EnemySpawnerData.EnemyMap[parent].TakeDamage(0, PrevDirection); + EnemySpawnerData.EnemyMap[parent].Damage(0, PrevDirection, ActiveClass.HitBoxDraw.Knockback); } }