From 7f4556853fa728e531603b9b4d5d9f9f8c5145ce Mon Sep 17 00:00:00 2001 From: RochesterX Date: Thu, 17 Apr 2025 21:39:27 -0400 Subject: [PATCH] Hat animation --- Assets/.DS_Store | Bin 14340 -> 12292 bytes Assets/Animations/Hat.controller | 156 ++++++++++++ Assets/Animations/Hat.controller.meta | 8 + Assets/Animations/HatDie.anim | 177 +++++++++++++ Assets/Animations/HatDie.anim.meta | 8 + Assets/Animations/HatRespawn.anim | 177 +++++++++++++ Assets/Animations/HatRespawn.anim.meta | 8 + Assets/Prefabs/Hat.prefab | 252 +++++++++++-------- Assets/Scenes/Platformer With Headroom.unity | 2 +- Assets/Scripts/Game/HatRespawn.cs | 123 +++++---- Assets/Scripts/Player/UseItem.cs | 4 +- Assets/Sprites/flag.png.meta | 29 ++- Assets/Sprites/hat.png.meta | 29 ++- 13 files changed, 816 insertions(+), 157 deletions(-) create mode 100644 Assets/Animations/Hat.controller create mode 100644 Assets/Animations/Hat.controller.meta create mode 100644 Assets/Animations/HatDie.anim create mode 100644 Assets/Animations/HatDie.anim.meta create mode 100644 Assets/Animations/HatRespawn.anim create mode 100644 Assets/Animations/HatRespawn.anim.meta diff --git a/Assets/.DS_Store b/Assets/.DS_Store index 7f8655bf75fda21144a332975d9ddc560a8cac98..f77eafa1965b987e9bd0871e60c0a3817b289359 100644 GIT binary patch delta 219 zcmZoEXh~3DU|?W$DortDV9)?EIe-{M3-ADmb_NCo?uiQeq974wpdbT75kn?J0YeEx zF@xU3i^`J?OjuYMfs!nfc?2vcdn#Bkvog4CyvWSHnVo}$gOO{qi@ z-mDP8K5?R~77s%(&z>% delta 199 zcmZokXem%&U|?W$DortDU@!nOIe-{M3-ADmHU().enabled = false; - if (isDropped && Time.time - lastInteractionTime > respawnTime) + public Vector2 initialSubhatPosition; + + + public static bool canBePickedUp = true; // Flag to check if the hat can be picked up + + public Vector2 initialScale; + + private void Awake() { - RespawnHat(); + initialScale = transform.lossyScale; + } + + void Start() + { + //initialSubhatPosition = transform.GetChild(0).transform.localPosition; + lastInteractionTime = Time.time; + isDropped = false; + transform.position = GameManager.Instance.hatSpawnPositions[Random.Range(0, GameManager.Instance.hatSpawnPositions.Count - 1)]; + } + + void Update() // Checks if the hat has been inactive for too long + { + if (GameManager.Instance.gameOver) GetComponent().enabled = false; + if (isDropped && Time.time - lastInteractionTime > respawnTime) + { + RespawnHat(); + } + } + + void OnTriggerEnter2D(Collider2D collision) // Respawns the hat if it falls out of bounds + { + if (collision.gameObject.CompareTag("Platformer Hazard")) + { + StartCoroutine(RespawnHat()); + } + } + + public void Interact() // Updates the player interaction time + { + lastInteractionTime = Time.time; + isDropped = false; + } + + public void OnHatDropped() // Resets the timer when the hat is dropped + { + lastInteractionTime = Time.time; + isDropped = true; + } + + private IEnumerator RespawnHat() // Respawns the hat at the designated spawn position + { + GetComponentInChildren().SetTrigger("respawn"); + + yield return new WaitForSeconds(1f / 3f / 2f); + + transform.position = GameManager.Instance.hatSpawnPositions[Random.Range(0, GameManager.Instance.hatSpawnPositions.Count - 1)]; + GetComponent().linearVelocity = Vector2.zero; + GetComponent().angularVelocity = 0f; + transform.rotation = Quaternion.identity; + lastInteractionTime = Time.time; // Reset the timer after respawning + isDropped = false; } } - - void OnTriggerEnter2D(Collider2D collision) // Respawns the hat if it falls out of bounds - { - if (collision.gameObject.CompareTag("Platformer Hazard")) - { - RespawnHat(); - } - } - - public void Interact() // Updates the player interaction time - { - lastInteractionTime = Time.time; - isDropped = false; - } - - public void OnHatDropped() // Resets the timer when the hat is dropped - { - lastInteractionTime = Time.time; - isDropped = true; - } - - private void RespawnHat() // Respawns the hat at the designated spawn position - { - transform.position = GameManager.Instance.hatSpawnPositions[Random.Range(0, GameManager.Instance.hatSpawnPositions.Count - 1)]; - GetComponent().linearVelocity = Vector2.zero; - GetComponent().angularVelocity = 0f; - transform.rotation = Quaternion.identity; - lastInteractionTime = Time.time; // Reset the timer after respawning - isDropped = false; - } -} } \ No newline at end of file diff --git a/Assets/Scripts/Player/UseItem.cs b/Assets/Scripts/Player/UseItem.cs index 705d516..c8be9e7 100644 --- a/Assets/Scripts/Player/UseItem.cs +++ b/Assets/Scripts/Player/UseItem.cs @@ -59,7 +59,7 @@ namespace Player item.transform.parent = head; item.transform.localRotation = Quaternion.identity; item.transform.localPosition = Vector3.zero; - item.transform.GetChild(0).transform.localPosition = item.GetComponent().initialSubhatPosition; + //item.transform.GetChild(0).transform.localPosition = item.GetComponent().initialSubhatPosition; if (!GameManager.playerHoldTimes.ContainsKey(gameObject)) { GameManager.playerHoldTimes[gameObject] = 0f; @@ -79,7 +79,7 @@ namespace Player StartCoroutine(WaitForInteractability()); heldItem.GetComponent().bodyType = RigidbodyType2D.Dynamic; heldItem.GetComponent().AddForce(Vector2.up * Random.Range(10f, 30f) + Vector2.right * Random.Range(-10, 10), ForceMode2D.Impulse); - heldItem.GetComponent().AddTorque(Random.Range(-5, 5), ForceMode2D.Impulse); + heldItem.GetComponent().AddTorque(Random.Range(-1, 1), ForceMode2D.Impulse); heldItem.GetComponent().OnHatDropped(); heldItem.transform.parent = GameManager.Instance.transform; heldItem = null; diff --git a/Assets/Sprites/flag.png.meta b/Assets/Sprites/flag.png.meta index 245b2e9..ce57704 100644 --- a/Assets/Sprites/flag.png.meta +++ b/Assets/Sprites/flag.png.meta @@ -109,6 +109,32 @@ TextureImporter: ignorePlatformSupport: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 4 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 4 + buildTarget: iOS + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 spriteSheet: serializedVersion: 2 sprites: @@ -147,7 +173,8 @@ TextureImporter: secondaryTextures: [] spriteCustomMetadata: entries: [] - nameFileIdTable: {} + nameFileIdTable: + flag_0: -5154189640090123692 mipmapLimitGroupName: pSDRemoveMatte: 0 userData: diff --git a/Assets/Sprites/hat.png.meta b/Assets/Sprites/hat.png.meta index c709ef2..21ce581 100644 --- a/Assets/Sprites/hat.png.meta +++ b/Assets/Sprites/hat.png.meta @@ -109,6 +109,32 @@ TextureImporter: ignorePlatformSupport: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 4 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 4 + buildTarget: iOS + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 spriteSheet: serializedVersion: 2 sprites: @@ -147,7 +173,8 @@ TextureImporter: secondaryTextures: [] spriteCustomMetadata: entries: [] - nameFileIdTable: {} + nameFileIdTable: + hat_0: 3063841963128474276 mipmapLimitGroupName: pSDRemoveMatte: 0 userData: