Feat: Dash

Implemented basic dash logic WITHOUT cooldowns. Needs more changes down the line
This commit is contained in:
2025-08-28 01:40:22 +02:00
parent 9a70b0bd2a
commit 685e0e1d2e
5 changed files with 69 additions and 27 deletions

View File

@@ -11,11 +11,14 @@ public class PlayerMovement : MonoBehaviour
private CharacterController controller;
private Vector3 velocity;
private Vector3 move;
private PlayerSkillTree PlayerSkills;
private PlayerSkillHandler playerSkillHandler;
private void Awake()
{
PlayerSkills = PlayerSkillTree.Instance;
playerSkillHandler = new PlayerSkillHandler();
}
void Start()
@@ -27,7 +30,13 @@ public class PlayerMovement : MonoBehaviour
{
if (Input.GetKeyDown(KeyCode.Space))
{
HandleDash();
/* Ugly part here, need to rewrite later */
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));
}
if (Input.GetKeyDown(KeyCode.L))
@@ -45,6 +54,15 @@ public class PlayerMovement : MonoBehaviour
void FixedUpdate()
{
if (playerSkillHandler.IsDashing())
{
Physics.IgnoreLayerCollision(6, 7, true);
}
else
{
Physics.IgnoreLayerCollision(6, 7, false);
}
HandleMovement();
ApplyGravity();
}
@@ -53,7 +71,7 @@ public class PlayerMovement : MonoBehaviour
{
float moveX = Input.GetAxisRaw("Horizontal");
float moveZ = Input.GetAxisRaw("Vertical");
Vector3 move = new Vector3(moveX, 0, moveZ).normalized;
move = new Vector3(moveX, 0, moveZ).normalized;
if (move.magnitude >= 0.1f)
{
@@ -66,19 +84,6 @@ public class PlayerMovement : MonoBehaviour
}
}
void HandleDash()
{
if (PlayerSkills.IsSkillUnlocked(PlayerSkillTree.Skills.Dash))
{
// Implement dash logic
Debug.Log("Dashing!");
}
else
{
Debug.Log("Dash skill is not unlocked.");
}
}
void ApplyGravity()
{
if (IsGrounded() && velocity.y < 0) velocity.y = -2f;

View File

@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerSkillHandler
{
private float dashSpeed = 15f;
private float dashDuration = 0.2f;
private bool isDashing = false;
public bool IsDashing() { return isDashing; }
public IEnumerator DashCoroutine(CharacterController controller, Vector3 direction)
{
float startTime = Time.time;
isDashing = true;
while (Time.time - startTime < dashDuration)
{
controller.Move(direction * dashSpeed * Time.deltaTime);
yield return null;
}
isDashing = false;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: bf963ec282f9eff40b50054039952aee