From 70518b2b69c56d42beb4637df571cddce98db595 Mon Sep 17 00:00:00 2001 From: RochesterX Date: Fri, 31 Jan 2025 12:48:13 -0500 Subject: [PATCH] Functioning player movement, Persistent block needs to be implemented --- Assets/Animations/Bones/Block.anim | 298 +---------------------- Assets/Animations/Bones/Bones.controller | 53 +++- Assets/Prefabs/Bones.prefab | 111 +++++++++ Assets/Scripts/Block.cs | 15 +- Assets/Scripts/Damageable.cs | 12 +- Assets/Scripts/PlayerMovement.cs | 4 +- Assets/Scripts/Punch.cs | 2 +- 7 files changed, 189 insertions(+), 306 deletions(-) diff --git a/Assets/Animations/Bones/Block.anim b/Assets/Animations/Bones/Block.anim index a573c89..0b798d8 100644 --- a/Assets/Animations/Bones/Block.anim +++ b/Assets/Animations/Bones/Block.anim @@ -14,31 +14,6 @@ AnimationClip: m_RotationCurves: [] m_CompressedRotationCurves: [] m_EulerCurves: - - curve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: {x: 0, y: 0, z: 0} - inSlope: {x: 0, y: 0, z: 0} - outSlope: {x: 0, y: 0, z: 0} - tangentMode: 0 - weightedMode: 0 - inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} - outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} - - serializedVersion: 3 - time: 1 - value: {x: 0, y: 0, z: 0} - inSlope: {x: 0, y: 0, z: 0} - outSlope: {x: 0, y: 0, z: 0} - tangentMode: 0 - weightedMode: 0 - inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} - outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - path: - curve: serializedVersion: 2 m_Curve: @@ -532,32 +507,7 @@ AnimationClip: m_PostInfinity: 2 m_RotationOrder: 4 path: Torso/Leg R U/Leg R L - m_PositionCurves: - - curve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: {x: -2.16, y: 14.08, z: 0} - inSlope: {x: 0, y: 0, z: 0} - outSlope: {x: 0, y: 0, z: 0} - tangentMode: 0 - weightedMode: 0 - inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} - outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} - - serializedVersion: 3 - time: 1 - value: {x: -2.16, y: 14.08, z: 0} - inSlope: {x: 0, y: 0, z: 0} - outSlope: {x: 0, y: 0, z: 0} - tangentMode: 0 - weightedMode: 0 - inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} - outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - path: + m_PositionCurves: [] m_ScaleCurves: [] m_FloatCurves: [] m_PPtrCurves: [] @@ -640,24 +590,6 @@ AnimationClip: isPPtrCurve: 0 isIntCurve: 0 isSerializeReferenceCurve: 0 - - serializedVersion: 2 - path: 0 - attribute: 1 - script: {fileID: 0} - typeID: 4 - customType: 0 - isPPtrCurve: 0 - isIntCurve: 0 - isSerializeReferenceCurve: 0 - - serializedVersion: 2 - path: 0 - attribute: 4 - script: {fileID: 0} - typeID: 4 - customType: 4 - isPPtrCurve: 0 - isIntCurve: 0 - isSerializeReferenceCurve: 0 - serializedVersion: 2 path: 3869152129 attribute: 4 @@ -698,186 +630,6 @@ AnimationClip: m_HeightFromFeet: 0 m_Mirror: 0 m_EditorCurves: - - serializedVersion: 2 - curve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: -2.16 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1 - value: -2.16 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - attribute: m_LocalPosition.x - path: - classID: 4 - script: {fileID: 0} - flags: 0 - - serializedVersion: 2 - curve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 14.08 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1 - value: 14.08 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - attribute: m_LocalPosition.y - path: - classID: 4 - script: {fileID: 0} - flags: 0 - - serializedVersion: 2 - curve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - attribute: m_LocalPosition.z - path: - classID: 4 - script: {fileID: 0} - flags: 0 - - serializedVersion: 2 - curve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - attribute: localEulerAnglesRaw.x - path: - classID: 4 - script: {fileID: 0} - flags: 0 - - serializedVersion: 2 - curve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - attribute: localEulerAnglesRaw.y - path: - classID: 4 - script: {fileID: 0} - flags: 0 - - serializedVersion: 2 - curve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - attribute: localEulerAnglesRaw.z - path: - classID: 4 - script: {fileID: 0} - flags: 0 - serializedVersion: 2 curve: serializedVersion: 2 @@ -2515,8 +2267,8 @@ AnimationClip: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 - attribute: m_LocalEulerAngles.x - path: + attribute: m_LocalEulerAngles.z + path: Torso/Leg R U/Leg R L classID: 4 script: {fileID: 0} flags: 0 @@ -2528,7 +2280,7 @@ AnimationClip: m_PostInfinity: 2 m_RotationOrder: 4 attribute: m_LocalEulerAngles.y - path: + path: Torso/Leg R U/Leg R L classID: 4 script: {fileID: 0} flags: 0 @@ -2539,8 +2291,8 @@ AnimationClip: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 - attribute: m_LocalEulerAngles.z - path: + attribute: m_LocalEulerAngles.x + path: Torso/Leg R U/Leg R L classID: 4 script: {fileID: 0} flags: 0 @@ -2868,42 +2620,6 @@ AnimationClip: classID: 4 script: {fileID: 0} flags: 0 - - serializedVersion: 2 - curve: - serializedVersion: 2 - m_Curve: [] - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - attribute: m_LocalEulerAngles.x - path: Torso/Leg R U/Leg R L - classID: 4 - script: {fileID: 0} - flags: 0 - - serializedVersion: 2 - curve: - serializedVersion: 2 - m_Curve: [] - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - attribute: m_LocalEulerAngles.y - path: Torso/Leg R U/Leg R L - classID: 4 - script: {fileID: 0} - flags: 0 - - serializedVersion: 2 - curve: - serializedVersion: 2 - m_Curve: [] - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - attribute: m_LocalEulerAngles.z - path: Torso/Leg R U/Leg R L - classID: 4 - script: {fileID: 0} - flags: 0 - m_HasGenericRootTransform: 1 + m_HasGenericRootTransform: 0 m_HasMotionFloatCurves: 0 m_Events: [] diff --git a/Assets/Animations/Bones/Bones.controller b/Assets/Animations/Bones/Bones.controller index 8cfb45e..3f166ba 100644 --- a/Assets/Animations/Bones/Bones.controller +++ b/Assets/Animations/Bones/Bones.controller @@ -35,7 +35,8 @@ AnimatorState: m_Name: Block m_Speed: 1 m_CycleOffset: 0 - m_Transitions: [] + m_Transitions: + - {fileID: 3246710262204482345} m_StateMachineBehaviours: [] m_Position: {x: 50, y: 50, z: 0} m_IKOnFeet: 0 @@ -51,6 +52,31 @@ AnimatorState: m_MirrorParameter: m_CycleOffsetParameter: m_TimeParameter: +--- !u!1101 &-4535150155480257032 +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: Block + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: -5708178649659260609} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0.1 + m_TransitionOffset: 0 + m_ExitTime: 0.75 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 0 --- !u!1101 &-3289816270970516984 AnimatorStateTransition: m_ObjectHideFlags: 1 @@ -124,10 +150,11 @@ AnimatorStateMachine: m_Position: {x: 60, y: 80, z: 0} - serializedVersion: 1 m_State: {fileID: -5708178649659260609} - m_Position: {x: 60, y: -80, z: 0} + m_Position: {x: 50, y: -100, z: 0} m_ChildStateMachines: [] m_AnyStateTransitions: - {fileID: 5263795009836994554} + - {fileID: -4535150155480257032} m_EntryTransitions: [] m_StateMachineTransitions: {} m_StateMachineBehaviours: [] @@ -335,6 +362,28 @@ AnimatorState: m_MirrorParameter: m_CycleOffsetParameter: m_TimeParameter: +--- !u!1101 &3246710262204482345 +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: 1699472617733096240} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0 + m_TransitionOffset: 0 + m_ExitTime: 0.75 + m_HasExitTime: 1 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 --- !u!1102 &4390441580030614539 AnimatorState: serializedVersion: 6 diff --git a/Assets/Prefabs/Bones.prefab b/Assets/Prefabs/Bones.prefab index 37d5e67..83eb8b0 100644 --- a/Assets/Prefabs/Bones.prefab +++ b/Assets/Prefabs/Bones.prefab @@ -19,6 +19,8 @@ GameObject: - component: {fileID: 2344147968324054325} - component: {fileID: 8121950008105218343} - component: {fileID: 3303109471384786876} + - component: {fileID: 6769589999303328011} + - component: {fileID: 7837794651479557677} m_Layer: 0 m_Name: Bones m_TagString: Untagged @@ -41,6 +43,7 @@ Transform: m_Children: - {fileID: 5586015051149451479} - {fileID: 2063840941502744053} + - {fileID: 433891288162264128} - {fileID: 7290594200745798336} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -271,6 +274,36 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: terminalVelocity: -15 +--- !u!111 &6769589999303328011 +Animation: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1375850422501237868} + m_Enabled: 1 + serializedVersion: 4 + m_Animation: {fileID: 0} + m_Animations: [] + m_WrapMode: 0 + m_PlayAutomatically: 1 + m_AnimatePhysics: 0 + m_UpdateMode: 0 + m_CullingType: 0 +--- !u!114 &7837794651479557677 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1375850422501237868} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c8c9288561905664eade3f6b2634fc6d, type: 3} + m_Name: + m_EditorClassIdentifier: + cancelable: 1 + blockArea: {fileID: 4413221056628714154} --- !u!1 &1648017802882051395 GameObject: m_ObjectHideFlags: 0 @@ -641,6 +674,84 @@ MonoBehaviour: m_BlockingMask: serializedVersion: 2 m_Bits: 4294967295 +--- !u!1 &2643587497727427762 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 433891288162264128} + - component: {fileID: 4413221056628714154} + m_Layer: 0 + m_Name: Block Hitbox + m_TagString: Punch Hurtbox + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &433891288162264128 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2643587497727427762} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 1.4, y: 0.3, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 7009259675412950971} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!61 &4413221056628714154 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2643587497727427762} + m_Enabled: 1 + serializedVersion: 3 + m_Density: 1 + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_ForceSendLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ForceReceiveLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ContactCaptureLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_CallbackLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_CompositeOperation: 0 + m_CompositeOrder: 0 + m_Offset: {x: 0.38033098, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0, y: 0} + oldSize: {x: 0, y: 0} + newSize: {x: 0, y: 0} + adaptiveTilingThreshold: 0 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + m_Size: {x: 2.750043, y: 1.2534463} + m_EdgeRadius: 0 --- !u!1 &3572452013539030063 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Block.cs b/Assets/Scripts/Block.cs index fba714d..b50222f 100644 --- a/Assets/Scripts/Block.cs +++ b/Assets/Scripts/Block.cs @@ -5,12 +5,14 @@ using UnityEngine.InputSystem; [RequireComponent(typeof(Animation))] public class Block : MonoBehaviour { - public bool cancelable = true; + //public bool cancelable = true; [SerializeField] private BoxCollider2D blockArea; private InputActionAsset actions; private Animation animationComponent; + public bool blocking = false; + private void Start() { actions = GetComponent().actions; @@ -21,13 +23,14 @@ public class Block : MonoBehaviour { var blockAction = actions.FindAction("Block"); - if (blockAction.triggered) + if (blockAction.ReadValue() == 1f) { Debug.Log("Block action triggered!"); - if (!cancelable) return; + //if (!cancelable) return; - animationComponent.Play("Block"); + //animationComponent.Play("Block"); + GetComponent().Block(); DisableCancellation(); ActivateBlockArea(); @@ -50,12 +53,12 @@ public class Block : MonoBehaviour public void DisableCancellation() { - cancelable = false; + //cancelable = false; } public void EnableCancellation() { - cancelable = true; + //cancelable = true; } public bool IsBlocking() diff --git a/Assets/Scripts/Damageable.cs b/Assets/Scripts/Damageable.cs index 0352241..7f3e106 100644 --- a/Assets/Scripts/Damageable.cs +++ b/Assets/Scripts/Damageable.cs @@ -12,9 +12,12 @@ public class Damageable : MonoBehaviour { if (collision.gameObject.CompareTag("Punch Hurtbox")) { - print($"{name}: Ouch"); - Damage(); - Recoil(collision.transform.parent.gameObject); + if (GetComponent().blocking) + { + collision.gameObject.GetComponent().Damage(gameObject); + return; + } + Damage(collision.transform.parent.gameObject); } } @@ -24,9 +27,10 @@ public class Damageable : MonoBehaviour //damageSource.transform.localScale *= 1.1f; } - private void Damage() + public void Damage(GameObject source) { damage += force; + Recoil(source); } public void ResetDamage() diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index e6af880..0bdfe66 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -119,7 +119,7 @@ public class PlayerMovement : MonoBehaviour private void Jump() { - if (!punch.cancelable) return; + //if (!punch.cancelable) return; if (virtualButtonJumpLastFrame == 1f) { @@ -160,7 +160,7 @@ public class PlayerMovement : MonoBehaviour private void HorizontalMovement() { - if (!punch.cancelable) return; + //if (!punch.cancelable) return; body.AddForce(new Vector2(virtualAxisX * walkSpeed * walkSpeedFactor, 0), ForceMode2D.Force); diff --git a/Assets/Scripts/Punch.cs b/Assets/Scripts/Punch.cs index 2506899..b6c15fd 100644 --- a/Assets/Scripts/Punch.cs +++ b/Assets/Scripts/Punch.cs @@ -21,7 +21,7 @@ public class Punch : MonoBehaviour { if (actions.FindAction("Punch").ReadValue() == 1f) { - if (!cancelable) return; + //if (!cancelable) return; GetComponent().Punch(); DisableCancellation(); }