From b3ab81f7ebe6335f8c179103cbbb3be7d8ad393c Mon Sep 17 00:00:00 2001 From: allylikesfrogs Date: Fri, 5 May 2023 19:54:18 -0700 Subject: [PATCH] water --- Assets/Prefabs/Player.prefab | 5 ++--- Assets/Scenes/ClarinetScene.unity | 4 ++++ Assets/Scenes/MainMenu.unity | 2 +- Assets/Scripts/PlayerBehavior.cs | 23 ++++++++++++++--------- Assets/Scripts/PlayerController.cs | 17 +++++++++++++---- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index bec64c8..a58a994 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -545,13 +545,12 @@ 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 - isDash: 0 - bonk: 2 - isInWater: 0 dashForce: 1.2 + reflectForce: 2 cymbalAudio: {fileID: 264629194984044240} grapplingGun: {fileID: 3465910379319867675} grapplingRope: {fileID: 7648135587659148198} diff --git a/Assets/Scenes/ClarinetScene.unity b/Assets/Scenes/ClarinetScene.unity index 217d077..8815631 100644 --- a/Assets/Scenes/ClarinetScene.unity +++ b/Assets/Scenes/ClarinetScene.unity @@ -3845,6 +3845,10 @@ PrefabInstance: propertyPath: m_camera value: objectReference: {fileID: 519420031} + - target: {fileID: 3893791749692807526, guid: 576d3fc87874f426294e4bbacb171478, type: 3} + propertyPath: Data + value: + objectReference: {fileID: 11400000, guid: fec218a9d55267dedac6ebe31eab6dcd, type: 2} - target: {fileID: 3893791749692807526, guid: 576d3fc87874f426294e4bbacb171478, type: 3} propertyPath: bonk value: 1.5 diff --git a/Assets/Scenes/MainMenu.unity b/Assets/Scenes/MainMenu.unity index bd2b345..eeb7636 100644 --- a/Assets/Scenes/MainMenu.unity +++ b/Assets/Scenes/MainMenu.unity @@ -914,7 +914,7 @@ PrefabInstance: m_Modifications: - target: {fileID: 2527389465697474493, guid: ff99a7d0beeca415e911378b9b377de4, type: 3} propertyPath: showDropdown - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 3422388587178177106, guid: ff99a7d0beeca415e911378b9b377de4, type: 3} propertyPath: m_Pivot.x diff --git a/Assets/Scripts/PlayerBehavior.cs b/Assets/Scripts/PlayerBehavior.cs index 5dd76a0..e52de17 100644 --- a/Assets/Scripts/PlayerBehavior.cs +++ b/Assets/Scripts/PlayerBehavior.cs @@ -5,6 +5,8 @@ using UnityEngine.InputSystem; public class PlayerBehavior : MonoBehaviour { + public PlayerData Data; + [Header("Physics:")] private float _hInput; private Rigidbody2D _rb; @@ -20,7 +22,7 @@ public class PlayerBehavior : MonoBehaviour [Header("Clarinet:")] bool unlockedClarinet; // things for dash - public bool isDash = false; + private bool isDash = false; public float dashForce = 1.2f; private float dashTime = 1.0f; private float dashInc = 0.1f; @@ -29,8 +31,8 @@ public class PlayerBehavior : MonoBehaviour // things for bounce public float reflectForce = 2f; private Vector2 saveVelocity; - public bool isInWater = false; - private bool lowSpeed = false; + private bool isInWater = false; + private bool hasBounced = false; [Header("Cymbals:")] private float cymbalActiveTime = 0f; @@ -109,7 +111,7 @@ public class PlayerBehavior : MonoBehaviour unlockedClarinet = StateController.Instance.HasClarinet(); if (playerIsAlive && unlockedClarinet) { - if (playerInput.actions["ClarinetDive"].WasPressedThisFrame()) + if (playerInput.actions["ClarinetDive"].WasPressedThisFrame() && !isInWater) { isDash = true; playerInput.DeactivateInput(); @@ -262,30 +264,31 @@ public class PlayerBehavior : MonoBehaviour } void Bounce() - {/* + { Vector2 reflect; - if (Mathf.Abs(saveVelocity.y) < 1f) + if (Mathf.Abs(saveVelocity.y) < 1f && hasBounced) { reflect = Vector2.zero; } else { reflect = new Vector2(saveVelocity.x, -(saveVelocity.y) * reflectForce); + hasBounced = true; } _rb.AddForce(reflect, ForceMode2D.Impulse); reflect = Vector2.zero; - isDash = false;*/ + isDash = false; } void Water() { - /*if(isDash) + if(isDash) { saveVelocity = _rb.velocity; } else { - + playerController.FloatGravity(); } /* if (Mathf.Abs(_rb.velocity.y) < 2f) @@ -363,7 +366,9 @@ public class PlayerBehavior : MonoBehaviour { isInWater = false; isDash = false; + hasBounced = false; playerInput.ActivateInput(); + playerController.EndFloatGravity(); saveVelocity = Vector2.zero; } } diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 620a7a2..d602b19 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -39,6 +39,8 @@ public class PlayerMovement : MonoBehaviour GameObject trumpetAnimationObject; bool trumpetActive = false; + //clarinet + private float tempFallSpeed; //Jump private bool _isJumpCut; @@ -91,6 +93,7 @@ public class PlayerMovement : MonoBehaviour { SetGravityScale(Data.gravityScale); IsFacingRight = true; + tempFallSpeed = Data.maxFallSpeed; } void OnMove(InputValue value) @@ -313,10 +316,6 @@ public class PlayerMovement : MonoBehaviour //Caps maximum fall speed, so when falling over large distances we don't accelerate to insanely high speeds RB.velocity = new Vector2(RB.velocity.x, Mathf.Max(RB.velocity.y, -Data.maxFallSpeed)); } - /*else if (playerBehavior.isInWater) - { - SetGravityScale(0); - }*/ else { //Default gravity if standing on a platform or moving upwards @@ -563,6 +562,16 @@ public class PlayerMovement : MonoBehaviour // print(Physics2D.OverlapBox(this.transform.position, _groundCheckSize, 0, _groundLayer) && !IsJumping); return (Physics2D.OverlapBox(new Vector2(this.transform.position.x, this.transform.position.y - _groundCheckOffset), _groundCheckSize, 0, _groundLayer) && !IsJumping); } + + public void FloatGravity() + { + Data.maxFallSpeed = 0.1f; + } + + public void EndFloatGravity() + { + Data.maxFallSpeed = tempFallSpeed; + } #endregion