diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index a58a994..61f4386 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -545,12 +545,14 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b0115312556794123a3cafad4b83d0a7, type: 3} m_Name: m_EditorClassIdentifier: - Data: {fileID: 11400000, guid: fec218a9d55267dedac6ebe31eab6dcd, type: 2} playerInput: {fileID: 1407172087} launcher: {fileID: 6559806128767475056} hasTambourine: 1 - dashForce: 1.2 + dashForce: 50 + dashTime: 1 reflectForce: 2 + waterGravity: 0.5 + velocityCut: 1.5 cymbalAudio: {fileID: 264629194984044240} grapplingGun: {fileID: 3465910379319867675} grapplingRope: {fileID: 7648135587659148198} diff --git a/Assets/Scripts/PlayerBehavior.cs b/Assets/Scripts/PlayerBehavior.cs index 213bca4..5458394 100644 --- a/Assets/Scripts/PlayerBehavior.cs +++ b/Assets/Scripts/PlayerBehavior.cs @@ -21,10 +21,11 @@ public class PlayerBehavior : MonoBehaviour bool unlockedClarinet; // things for dash private bool isDash = false; - public float dashForce = 1.3f; - private float dashTime = 1.0f; + public float dashForce = 1f; + public float dashTime = 1.0f; private float dashInc = 0.1f; private float currentDash = 0.0f; + private bool forceAdded = false; Vector2 dashVec; // things for bounce public float reflectForce = 1.1f; @@ -32,6 +33,7 @@ public class PlayerBehavior : MonoBehaviour private bool isInWater = false; private bool hasBounced = false; public float waterGravity = 0.5f; + public float velocityCut = 1f; [Header("Cymbals:")] private float cymbalActiveTime = 0f; @@ -78,16 +80,16 @@ public class PlayerBehavior : MonoBehaviour void Update() { - if (this.cymbalActiveTime < 0) - { - this.gameUI.ToggleCymbal(true); - } - this.cymbalActiveTime -= Time.deltaTime; - - unlockedTambourine = StateController.Instance.HasTambourine(); if (playerIsAlive) { + if (this.cymbalActiveTime < 0) + { + this.gameUI.ToggleCymbal(true); + } + this.cymbalActiveTime -= Time.deltaTime; + // throw tambourine + unlockedTambourine = StateController.Instance.HasTambourine(); if (playerInput.actions["ThrowTambourine"].WasPressedThisFrame()) { ThrowTambourine(); @@ -104,62 +106,65 @@ public class PlayerBehavior : MonoBehaviour LetGoOfGrapple(); } + // clarinet + unlockedClarinet = StateController.Instance.HasClarinet(); + if (unlockedClarinet) + { + if (playerInput.actions["ClarinetDive"].WasPressedThisFrame() && !isInWater && !playerController.IsGrounded()) + { + isDash = true; + playerInput.DeactivateInput(); + currentDash = 0.0f; + } + + if (!playerController.IsGrounded() && isDash && (currentDash < dashTime)) + { + if (!forceAdded) { + dashVec = new Vector2(1f * forward, -1f) * dashForce; + _rb.AddForce(dashVec, ForceMode2D.Impulse); + forceAdded = true; + } + + currentDash += Time.deltaTime; + } + else if ((currentDash >= dashTime)) // dash ends + { + if (!isInWater) { + isDash = false; + forceAdded = false; + _rb.AddForce(-(dashVec), ForceMode2D.Impulse); + playerInput.ActivateInput(); + } + currentDash = 0.0f; + dashVec = Vector2.zero; + } + else { + isDash = false; + forceAdded = false; + playerInput.ActivateInput(); + currentDash = 0.0f; + dashVec = Vector2.zero; + } + } + + if (StateController.Instance.HasCymbal()) + { + if (this.playerInput.actions["CymbalCrash"].WasPressedThisFrame()) + { + // Play the sound + this.gameUI.ToggleCymbal(false); + // this.audioSource.clip = cymbalSound; + // this.audioSource.loop = false; + // this.audioSource.Play(); + cymbalAudio.Play(); + + // Set the cymbal active for the equivalent of one second + this.cymbalActiveTime = 1; + } + } + Animate(); } - - unlockedClarinet = StateController.Instance.HasClarinet(); - if (playerIsAlive && unlockedClarinet) - { - if (playerInput.actions["ClarinetDive"].WasPressedThisFrame() && !isInWater) - { - isDash = true; - playerInput.DeactivateInput(); - currentDash = 0.0f; - } - if (!playerController.IsGrounded() && isDash && (currentDash < dashTime)) - { - if (forward == 1) - { - dashVec = new Vector2(1f, -1f) * dashForce; - _rb.AddForce(dashVec, ForceMode2D.Impulse); - } - else - { - dashVec = new Vector2(-1f, -1f) * dashForce; - _rb.AddForce(dashVec, ForceMode2D.Impulse); - } - currentDash += dashInc; - } - else if ((currentDash == dashTime || currentDash > dashTime) && !isInWater) - { - isDash = false; - currentDash = 0.0f; - _rb.AddForce(-(dashVec), ForceMode2D.Impulse); - dashVec = Vector2.zero; - playerInput.ActivateInput(); - } - else - { - currentDash = 0.0f; - dashVec = Vector2.zero; - } - } - - if (StateController.Instance.HasCymbal()) - { - if (this.playerInput.actions["CymbalCrash"].WasPressedThisFrame()) - { - // Play the sound - this.gameUI.ToggleCymbal(false); - // this.audioSource.clip = cymbalSound; - // this.audioSource.loop = false; - // this.audioSource.Play(); - cymbalAudio.Play(); - - // Set the cymbal active for the equivalent of one second - this.cymbalActiveTime = 1; - } - } } void Animate() @@ -201,13 +206,6 @@ public class PlayerBehavior : MonoBehaviour } - void FlipScale() - { // DOENST WORK RIGHT (that's so sad for you) - Vector3 currentScale = this.gameObject.transform.localScale; - currentScale.x *= -1; - this.gameObject.transform.localScale = currentScale; - } - void FlipRenderer() { GetComponent().flipX = !GetComponent().flipX; @@ -285,7 +283,11 @@ public class PlayerBehavior : MonoBehaviour print("water dash " + isDash); if(isDash) { - saveVelocity = _rb.velocity; + saveVelocity = _rb.velocity / velocityCut; + if (isDash) { + dashVec = new Vector2(1f * forward, -1f) * (dashForce / velocityCut); + _rb.AddForce(dashVec, ForceMode2D.Force); + } } else {