From af38398c28fb401b99c4f91c9d6d422a08ecbe7a Mon Sep 17 00:00:00 2001 From: cemt1363 Date: Sat, 6 Jun 2026 01:33:59 +0200 Subject: [PATCH] dash and jump almost final version --- Game/Assets/Scripts/DropletMovement.cs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Game/Assets/Scripts/DropletMovement.cs b/Game/Assets/Scripts/DropletMovement.cs index 8ea16a3..acffae5 100644 --- a/Game/Assets/Scripts/DropletMovement.cs +++ b/Game/Assets/Scripts/DropletMovement.cs @@ -5,15 +5,18 @@ public class DropletMovement : MonoBehaviour { private Rigidbody2D rb; + // helper variables + private bool isGrounded = true; + private float facingDirection = 1f; + + // movement + private Vector2 movement; public float jumpingPower = 5f; public float moveSpeed = 5f; - private Vector2 movement; - private bool isGrounded = true; - + // dashing private bool canDash = true; private bool isDashing; - public float dashingPower = 24f; public float dashingTime = 0.2f; public float dashingCooldown = 1f; @@ -34,6 +37,9 @@ public class DropletMovement : MonoBehaviour movement.x = Input.GetAxisRaw("Horizontal"); + if (movement.x < 0) facingDirection = -1; + if (movement.x > 0) facingDirection = 1; + if (isGrounded && (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) || @@ -87,4 +93,14 @@ public class DropletMovement : MonoBehaviour canDash = true; } + + private void OnCollisionEnter2D(Collision2D col) + { + isGrounded = true; + } + + private void OnCollisionExit2D(Collision2D col) + { + isGrounded = false; + } } \ No newline at end of file