From dc083bfc93d7792708959bebd59306b28142f8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20P=C4=9Bnkava?= Date: Thu, 28 Aug 2025 17:09:35 +0200 Subject: [PATCH] Refactor: Dash Repositioned some parts of dash code into skillHandler --- .../Assets/Prefabs/PlayerContainer.prefab | 2 ++ .../Assets/Scripts/Player/PlayerMovement.cs | 17 +++++---------- .../Scripts/Player/PlayerSkillHandler.cs | 21 ++++++++++++------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/3D blobici/Assets/Prefabs/PlayerContainer.prefab b/3D blobici/Assets/Prefabs/PlayerContainer.prefab index 827c64a..0e32f08 100644 --- a/3D blobici/Assets/Prefabs/PlayerContainer.prefab +++ b/3D blobici/Assets/Prefabs/PlayerContainer.prefab @@ -608,6 +608,8 @@ MonoBehaviour: sprintSpeed: 10 gravity: -9.81 rotationSpeed: 10 + dashSpeed: 15 + dashDuration: 0.25 --- !u!143 &1781483820777133190 CharacterController: m_ObjectHideFlags: 0 diff --git a/3D blobici/Assets/Scripts/Player/PlayerMovement.cs b/3D blobici/Assets/Scripts/Player/PlayerMovement.cs index 8e7c709..feb20a5 100644 --- a/3D blobici/Assets/Scripts/Player/PlayerMovement.cs +++ b/3D blobici/Assets/Scripts/Player/PlayerMovement.cs @@ -9,6 +9,9 @@ public class PlayerMovement : MonoBehaviour public float gravity = -9.81f; public float rotationSpeed = 10f; + public float dashSpeed; + public float dashDuration; + private CharacterController controller; private Vector3 velocity; private Vector3 move; @@ -18,7 +21,7 @@ public class PlayerMovement : MonoBehaviour private void Awake() { PlayerSkills = PlayerSkillTree.Instance; - playerSkillHandler = new PlayerSkillHandler(); + playerSkillHandler = new PlayerSkillHandler(dashSpeed, dashDuration); } void Start() @@ -30,10 +33,9 @@ public class PlayerMovement : MonoBehaviour { if (Input.GetKeyDown(KeyCode.Space)) { - /* Ugly part here, need to rewrite later */ + /* Get the input for horizontal and vertical movement */ float moveX = Input.GetAxisRaw("Horizontal"); float moveZ = Input.GetAxisRaw("Vertical"); - /* End of the ugly part :P */ move = new Vector3(moveX, 0, moveZ).normalized; StartCoroutine(playerSkillHandler.DashCoroutine(controller, move)); @@ -54,15 +56,6 @@ public class PlayerMovement : MonoBehaviour void FixedUpdate() { - if (playerSkillHandler.IsDashing()) - { - Physics.IgnoreLayerCollision(6, 7, true); - } - else - { - Physics.IgnoreLayerCollision(6, 7, false); - } - HandleMovement(); ApplyGravity(); } diff --git a/3D blobici/Assets/Scripts/Player/PlayerSkillHandler.cs b/3D blobici/Assets/Scripts/Player/PlayerSkillHandler.cs index 4fbe47a..6f03c89 100644 --- a/3D blobici/Assets/Scripts/Player/PlayerSkillHandler.cs +++ b/3D blobici/Assets/Scripts/Player/PlayerSkillHandler.cs @@ -4,24 +4,31 @@ using UnityEngine; public class PlayerSkillHandler { - private float dashSpeed = 15f; - private float dashDuration = 0.2f; + private float dashSpeed; + private float dashDuration; private bool isDashing = false; public bool IsDashing() { return isDashing; } + public PlayerSkillHandler(float dashSpeed, float dashDuration) + { + this.dashSpeed = dashSpeed; + this.dashDuration = dashDuration; + } + public IEnumerator DashCoroutine(CharacterController controller, Vector3 direction) { - + Physics.IgnoreLayerCollision(6, 7, true); // disable collisions between player and enemies float startTime = Time.time; - isDashing = true; + isDashing = true; // just for now. maybe will be removed while (Time.time - startTime < dashDuration) { - controller.Move(direction * dashSpeed * Time.deltaTime); - yield return null; + controller.Move(dashSpeed * Time.deltaTime * direction); + yield return null; // wait one frame } - isDashing = false; + isDashing = false; // just for now. maybe will be removed + Physics.IgnoreLayerCollision(6, 7, false); // enable collisions between player and enemies } }