From f57c7313c6ed1ba01ca79c27b8054a527f781c26 Mon Sep 17 00:00:00 2001 From: Walter Date: Sun, 1 Feb 2026 14:27:47 -0600 Subject: [PATCH] added self heal --- Assets/InputSystem_Actions.inputactions | 82 +++++- Assets/Prefabs/Player.prefab | 24 ++ Assets/Scenes/Experiment.unity | 250 ++----------------- Assets/Scripts/PlayerPickupController.cs | 2 +- Assets/Scripts/PlayerPlatformerController.cs | 42 +++- 5 files changed, 167 insertions(+), 233 deletions(-) diff --git a/Assets/InputSystem_Actions.inputactions b/Assets/InputSystem_Actions.inputactions index aa0e1f3..0decd8c 100644 --- a/Assets/InputSystem_Actions.inputactions +++ b/Assets/InputSystem_Actions.inputactions @@ -32,6 +32,15 @@ "processors": "", "interactions": "", "initialStateCheck": false + }, + { + "name": "Heal", + "type": "Button", + "id": "96a3c855-05a0-4431-961e-d2552c539bf0", + "expectedControlType": "", + "processors": "", + "interactions": "", + "initialStateCheck": false } ], "bindings": [ @@ -221,6 +230,17 @@ "action": "Interact", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "95d44eae-cbf8-4ad2-9dc3-9e8524118e9f", + "path": "/buttonNorth", + "interactions": "", + "processors": "", + "groups": ";Gamepad", + "action": "Heal", + "isComposite": false, + "isPartOfComposite": false } ] }, @@ -254,6 +274,15 @@ "processors": "", "interactions": "", "initialStateCheck": false + }, + { + "name": "Heal", + "type": "Button", + "id": "d384b3b4-cc86-4a73-a97f-0d04e31417a8", + "expectedControlType": "", + "processors": "", + "interactions": "", + "initialStateCheck": false } ], "bindings": [ @@ -268,6 +297,17 @@ "isComposite": false, "isPartOfComposite": false }, + { + "name": "", + "id": "d952c2fd-e0f5-4ab9-bbbd-2af129855725", + "path": "/buttonNorth", + "interactions": "", + "processors": "", + "groups": ";Gamepad", + "action": "Heal", + "isComposite": false, + "isPartOfComposite": false + }, { "name": "", "id": "0bb7b65d-0e9d-4a2a-8bd4-35a4d9f5b7a2", @@ -322,6 +362,15 @@ "processors": "", "interactions": "", "initialStateCheck": false + }, + { + "name": "Heal", + "type": "Button", + "id": "56e697eb-9ef8-4e3d-9671-74da02a08793", + "expectedControlType": "", + "processors": "", + "interactions": "", + "initialStateCheck": false } ], "bindings": [ @@ -336,6 +385,17 @@ "isComposite": false, "isPartOfComposite": false }, + { + "name": "", + "id": "bcba7833-70cc-40cf-aa96-a824333c9112", + "path": "/buttonNorth", + "interactions": "", + "processors": "", + "groups": ";Gamepad", + "action": "Heal", + "isComposite": false, + "isPartOfComposite": false + }, { "name": "", "id": "a91fe28e-bdb1-4a19-b09b-9bb52dc0940c", @@ -390,6 +450,15 @@ "processors": "", "interactions": "", "initialStateCheck": false + }, + { + "name": "Heal", + "type": "Button", + "id": "7eee99e7-4426-4f8f-812f-0562adbbbbd3", + "expectedControlType": "", + "processors": "", + "interactions": "", + "initialStateCheck": false } ], "bindings": [ @@ -404,6 +473,17 @@ "isComposite": false, "isPartOfComposite": false }, + { + "name": "", + "id": "f5d22357-bf6c-456d-95bb-057bd7d482f9", + "path": "/buttonNorth", + "interactions": "", + "processors": "", + "groups": ";Gamepad", + "action": "Heal", + "isComposite": false, + "isPartOfComposite": false + }, { "name": "", "id": "0f15df45-ecb7-4a35-8e06-293d50b89001", @@ -1007,4 +1087,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 1c89edd..ec71099 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -16,6 +16,7 @@ GameObject: - component: {fileID: 7763498473808654306} - component: {fileID: 3659140714710275197} - component: {fileID: 9133098163257611752} + - component: {fileID: 4619270190355407300} m_Layer: 6 m_Name: Player m_TagString: Untagged @@ -199,6 +200,7 @@ MonoBehaviour: actionMapName: Player moveActionName: Move jumpActionName: Jump + healActionName: Heal controlSchemeName: Gamepad gamepadIndex: 0 moveSpeed: 6 @@ -251,6 +253,28 @@ MonoBehaviour: isPanicking: 0 isParalyzed: 0 paralyseDuration: 1.2 +--- !u!95 &4619270190355407300 +Animator: + serializedVersion: 7 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3937090937419967315} + m_Enabled: 1 + m_Avatar: {fileID: 0} + m_Controller: {fileID: 9100000, guid: 86632cb6b3835a44e87fb6f039478d61, type: 2} + m_CullingMode: 0 + m_UpdateMode: 0 + m_ApplyRootMotion: 0 + m_LinearVelocityBlending: 0 + m_StabilizeFeet: 0 + m_AnimatePhysics: 0 + m_WarningMessage: + m_HasTransformHierarchy: 1 + m_AllowConstantClipSamplingOptimization: 1 + m_KeepAnimatorStateOnDisable: 0 + m_WriteDefaultValuesOnDisable: 0 --- !u!1 &6898135930931977916 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Experiment.unity b/Assets/Scenes/Experiment.unity index 24e561e..08837c3 100644 --- a/Assets/Scenes/Experiment.unity +++ b/Assets/Scenes/Experiment.unity @@ -203,6 +203,10 @@ PrefabInstance: propertyPath: actionMapName value: Player2 objectReference: {fileID: 0} + - target: {fileID: 7763498473808654306, guid: 414ae949bae840c4589b38dd91c715e0, type: 3} + propertyPath: healActionName + value: Heal + objectReference: {fileID: 0} - target: {fileID: 7763498473808654306, guid: 414ae949bae840c4589b38dd91c715e0, type: 3} propertyPath: controlSchemeName value: Gamepad @@ -400,6 +404,14 @@ PrefabInstance: propertyPath: actionMapName value: Player2 objectReference: {fileID: 0} + - target: {fileID: 7763498473808654306, guid: 414ae949bae840c4589b38dd91c715e0, type: 3} + propertyPath: healActionName + value: Heal + objectReference: {fileID: 0} + - target: {fileID: 7763498473808654306, guid: 414ae949bae840c4589b38dd91c715e0, type: 3} + propertyPath: jumpActionName + value: Jump + objectReference: {fileID: 0} - target: {fileID: 7763498473808654306, guid: 414ae949bae840c4589b38dd91c715e0, type: 3} propertyPath: controlSchemeName value: Gamepad @@ -425,120 +437,6 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 414ae949bae840c4589b38dd91c715e0, type: 3} ---- !u!1 &393625608 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 393625611} - - component: {fileID: 393625610} - - component: {fileID: 393625609} - m_Layer: 0 - m_Name: Trick_Run01 - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!95 &393625609 -Animator: - serializedVersion: 7 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 393625608} - m_Enabled: 1 - m_Avatar: {fileID: 0} - m_Controller: {fileID: 9100000, guid: c4f171c0550c83640bad4a8bc02f1c73, type: 2} - m_CullingMode: 0 - m_UpdateMode: 0 - m_ApplyRootMotion: 0 - m_LinearVelocityBlending: 0 - m_StabilizeFeet: 0 - m_AnimatePhysics: 0 - m_WarningMessage: - m_HasTransformHierarchy: 1 - m_AllowConstantClipSamplingOptimization: 1 - m_KeepAnimatorStateOnDisable: 0 - m_WriteDefaultValuesOnDisable: 0 ---- !u!212 &393625610 -SpriteRenderer: - serializedVersion: 2 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 393625608} - m_Enabled: 1 - m_CastShadows: 0 - m_ReceiveShadows: 0 - m_DynamicOccludee: 1 - m_StaticShadowCaster: 0 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 0 - m_RayTraceProcedural: 0 - m_RayTracingAccelStructBuildFlagsOverride: 0 - m_RayTracingAccelStructBuildFlags: 1 - m_SmallMeshCulling: 1 - m_ForceMeshLod: -1 - m_MeshLodSelectionBias: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 0 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_GlobalIlluminationMeshLod: 0 - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_MaskInteraction: 0 - m_Sprite: {fileID: 21300000, guid: 9c5273d0f7687334ba77aa78d87131b9, type: 3} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_FlipX: 0 - m_FlipY: 0 - m_DrawMode: 0 - m_Size: {x: 2.26, y: 2.86} - m_AdaptiveModeThreshold: 0.5 - m_SpriteTileMode: 0 - m_WasSpriteAssigned: 1 - m_SpriteSortPoint: 0 ---- !u!4 &393625611 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 393625608} - serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 7.804798, y: -2.2748086, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 0} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &418512664 GameObject: m_ObjectHideFlags: 0 @@ -1366,6 +1264,10 @@ PrefabInstance: propertyPath: m_Name value: Player (1) objectReference: {fileID: 0} + - target: {fileID: 7763498473808654306, guid: 414ae949bae840c4589b38dd91c715e0, type: 3} + propertyPath: healActionName + value: Heal + objectReference: {fileID: 0} - target: {fileID: 8870760143677714522, guid: 414ae949bae840c4589b38dd91c715e0, type: 3} propertyPath: m_Color.b value: 0.6462264 @@ -1711,120 +1613,6 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1063739947 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1063739950} - - component: {fileID: 1063739949} - - component: {fileID: 1063739948} - m_Layer: 0 - m_Name: P_Run01 - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!95 &1063739948 -Animator: - serializedVersion: 7 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1063739947} - m_Enabled: 1 - m_Avatar: {fileID: 0} - m_Controller: {fileID: 9100000, guid: 86632cb6b3835a44e87fb6f039478d61, type: 2} - m_CullingMode: 0 - m_UpdateMode: 0 - m_ApplyRootMotion: 0 - m_LinearVelocityBlending: 0 - m_StabilizeFeet: 0 - m_AnimatePhysics: 0 - m_WarningMessage: - m_HasTransformHierarchy: 1 - m_AllowConstantClipSamplingOptimization: 1 - m_KeepAnimatorStateOnDisable: 0 - m_WriteDefaultValuesOnDisable: 0 ---- !u!212 &1063739949 -SpriteRenderer: - serializedVersion: 2 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1063739947} - m_Enabled: 1 - m_CastShadows: 0 - m_ReceiveShadows: 0 - m_DynamicOccludee: 1 - m_StaticShadowCaster: 0 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 0 - m_RayTraceProcedural: 0 - m_RayTracingAccelStructBuildFlagsOverride: 0 - m_RayTracingAccelStructBuildFlags: 1 - m_SmallMeshCulling: 1 - m_ForceMeshLod: -1 - m_MeshLodSelectionBias: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 0 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_GlobalIlluminationMeshLod: 0 - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_MaskInteraction: 0 - m_Sprite: {fileID: 21300000, guid: c28a83d936216af40976803e59feffac, type: 3} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_FlipX: 0 - m_FlipY: 0 - m_DrawMode: 0 - m_Size: {x: 2.87, y: 3.58} - m_AdaptiveModeThreshold: 0.5 - m_SpriteTileMode: 0 - m_WasSpriteAssigned: 1 - m_SpriteSortPoint: 0 ---- !u!4 &1063739950 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1063739947} - serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 8.13, y: 2.32, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 0} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1118230342 GameObject: m_ObjectHideFlags: 0 @@ -1861,6 +1649,7 @@ MonoBehaviour: actionMapName: Player moveActionName: Move jumpActionName: Jump + healActionName: Heal controlSchemeName: gamepadIndex: -1 moveSpeed: 6 @@ -2436,6 +2225,10 @@ PrefabInstance: propertyPath: actionMapName value: Player2 objectReference: {fileID: 0} + - target: {fileID: 7763498473808654306, guid: 414ae949bae840c4589b38dd91c715e0, type: 3} + propertyPath: healActionName + value: Heal + objectReference: {fileID: 0} - target: {fileID: 7763498473808654306, guid: 414ae949bae840c4589b38dd91c715e0, type: 3} propertyPath: controlSchemeName value: Gamepad @@ -3111,4 +2904,3 @@ SceneRoots: - {fileID: 2100000101} - {fileID: 2200000001} - {fileID: 491328828} - - {fileID: 393625611} diff --git a/Assets/Scripts/PlayerPickupController.cs b/Assets/Scripts/PlayerPickupController.cs index 07d532b..6d27f17 100644 --- a/Assets/Scripts/PlayerPickupController.cs +++ b/Assets/Scripts/PlayerPickupController.cs @@ -192,7 +192,7 @@ public class PlayerPickupController : MonoBehaviour } } - void DropObject(bool applyThrow) + public void DropObject(bool applyThrow) { // Re-enable physics if (heldObject.TryGetComponent(out Rigidbody2D rb)) diff --git a/Assets/Scripts/PlayerPlatformerController.cs b/Assets/Scripts/PlayerPlatformerController.cs index 4609c84..189cffa 100644 --- a/Assets/Scripts/PlayerPlatformerController.cs +++ b/Assets/Scripts/PlayerPlatformerController.cs @@ -10,7 +10,7 @@ public class PlayerPlatformerController : MonoBehaviour [SerializeField] private string actionMapName = "Player"; [SerializeField] private string moveActionName = "Move"; [SerializeField] private string jumpActionName = "Jump"; - [SerializeField] private string healActionName = "Crouch"; + [SerializeField] private string healActionName = "Heal"; [SerializeField] private string controlSchemeName = ""; [SerializeField] private int gamepadIndex = -1; [SerializeField] private float moveSpeed = 6f; @@ -19,6 +19,7 @@ public class PlayerPlatformerController : MonoBehaviour [SerializeField] private float groundCheckDistance = 0.05f; private PlayerStressController playerStressController; + private PlayerPickupController playerPickupController; private Rigidbody2D body; private BoxCollider2D bodyCollider; @@ -28,12 +29,16 @@ public class PlayerPlatformerController : MonoBehaviour private InputAction healAction; public float LastMoveX { get; private set; } private bool deviceFilterEnabled; + private int healCoolDownTicks = 15; + private int currentHealCoolDown = 0; + private bool canHeal = true; private void Awake() { body = GetComponent(); bodyCollider = GetComponent(); playerStressController = GetComponent(); + playerPickupController = GetComponent(); } private void OnEnable() @@ -56,10 +61,12 @@ public class PlayerPlatformerController : MonoBehaviour var map = runtimeActions.FindActionMap(actionMapName, true); moveAction = map.FindAction(moveActionName, true); jumpAction = map.FindAction(jumpActionName, true); + healAction = map.FindAction(healActionName, true); moveAction.Enable(); jumpAction.Enable(); jumpAction.performed += OnJumpPerformed; + healAction.Enable(); } private void OnDisable() @@ -75,6 +82,11 @@ public class PlayerPlatformerController : MonoBehaviour moveAction.Disable(); } + if (healAction != null) + { + healAction.Disable(); + } + if (runtimeActions != null) { runtimeActions.Disable(); @@ -86,6 +98,16 @@ public class PlayerPlatformerController : MonoBehaviour private void FixedUpdate() { + if (healAction == null) return; + + currentHealCoolDown++; + + if (currentHealCoolDown >= healCoolDownTicks) + { + currentHealCoolDown = 0; + canHeal = true; + } + if (moveAction == null) { return; @@ -93,6 +115,22 @@ public class PlayerPlatformerController : MonoBehaviour if (playerStressController.isPanicking) return; + if (healAction.IsPressed()) + { + if(playerPickupController.heldObject != null) + { + playerPickupController.DropObject(false); + } + + if (canHeal) + { + playerStressController.ReduceStress(1f); + canHeal = false; + } + + return; + } + var input = moveAction.ReadValue(); if (Mathf.Abs(input.x) > 0.01f) { @@ -105,7 +143,7 @@ public class PlayerPlatformerController : MonoBehaviour private void OnJumpPerformed(InputAction.CallbackContext context) { - if (playerStressController.isPanicking) return; + if (playerStressController.isPanicking || healAction.IsPressed()) return; if (!IsGrounded()) {