From 342489922e8b122e8ca810a2cd83917e28c36bb3 Mon Sep 17 00:00:00 2001 From: cemt1363 Date: Sat, 6 Jun 2026 01:09:39 +0200 Subject: [PATCH 1/2] codes combined (dash and jump) --- Game/Assets/Scenes/cems scene.unity | 2 +- Game/Assets/Scripts/DropletMovement.cs | 75 +++++++++++++++++++++----- 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/Game/Assets/Scenes/cems scene.unity b/Game/Assets/Scenes/cems scene.unity index f47f316..4f44f2c 100644 --- a/Game/Assets/Scenes/cems scene.unity +++ b/Game/Assets/Scenes/cems scene.unity @@ -137,7 +137,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4266476263824402640, guid: d56297e435f8410a584581d73d99d2e4, type: 3} propertyPath: m_GravityScale - value: 5 + value: 1 objectReference: {fileID: 0} - target: {fileID: 6566899495513628888, guid: d56297e435f8410a584581d73d99d2e4, type: 3} propertyPath: m_LocalPosition.x diff --git a/Game/Assets/Scripts/DropletMovement.cs b/Game/Assets/Scripts/DropletMovement.cs index 9c47c33..8ea16a3 100644 --- a/Game/Assets/Scripts/DropletMovement.cs +++ b/Game/Assets/Scripts/DropletMovement.cs @@ -1,19 +1,24 @@ using UnityEngine; +using System.Collections; public class DropletMovement : MonoBehaviour { private Rigidbody2D rb; - public float moveSpeed = 5f; - public float jumpingPower = 5f; - private Vector2 movement; - private Animator playerAnim; //for animation - private float xInput; - //helper variables + public float jumpingPower = 5f; + public float moveSpeed = 5f; + + private Vector2 movement; private bool isGrounded = true; - [SerializeField] private float dashSpeed; - [SerializeField] private float dashDuration; - private float dashTime; + + private bool canDash = true; + private bool isDashing; + + public float dashingPower = 24f; + public float dashingTime = 0.2f; + public float dashingCooldown = 1f; + + [SerializeField] private TrailRenderer tr; void Start() { @@ -22,18 +27,64 @@ public class DropletMovement : MonoBehaviour void Update() { + if (isDashing) + { + return; + } + movement.x = Input.GetAxisRaw("Horizontal"); - - - if (isGrounded && Input.GetKeyDown(KeyCode.Space)) + if (isGrounded && + (Input.GetKeyDown(KeyCode.Space) || + Input.GetKeyDown(KeyCode.UpArrow) || + Input.GetKeyDown(KeyCode.W))) { rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpingPower); } + + if (Input.GetKeyDown(KeyCode.LeftShift) && canDash) + { + StartCoroutine(Dash()); + } } private void FixedUpdate() { + if (isDashing) + { + return; + } + rb.linearVelocity = new Vector2(movement.x * moveSpeed, rb.linearVelocity.y); } + + private IEnumerator Dash() + { + canDash = false; + isDashing = true; + + float originalGravity = rb.gravityScale; + rb.gravityScale = 0f; + + rb.linearVelocity = new Vector2(transform.localScale.x * dashingPower, 0f); + + if (tr != null) + { + tr.emitting = true; + } + + yield return new WaitForSeconds(dashingTime); + + if (tr != null) + { + tr.emitting = false; + } + + rb.gravityScale = originalGravity; + isDashing = false; + + yield return new WaitForSeconds(dashingCooldown); + + canDash = true; + } } \ No newline at end of file From af38398c28fb401b99c4f91c9d6d422a08ecbe7a Mon Sep 17 00:00:00 2001 From: cemt1363 Date: Sat, 6 Jun 2026 01:33:59 +0200 Subject: [PATCH 2/2] 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