From 4335c5db053fef5393fb35b5c2cf1496e37e9aab Mon Sep 17 00:00:00 2001 From: "kb2love@naver.com" <160492288+21acad@users.noreply.github.com> Date: Tue, 1 Apr 2025 22:53:33 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B0=80=EC=86=8D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/1_Script/Player/PlayerContoller.cs | 38 ++++++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/Assets/1_Script/Player/PlayerContoller.cs b/Assets/1_Script/Player/PlayerContoller.cs index ea59e74..af45505 100644 --- a/Assets/1_Script/Player/PlayerContoller.cs +++ b/Assets/1_Script/Player/PlayerContoller.cs @@ -6,6 +6,9 @@ public class PlayerController : MonoBehaviour public float moveSpeed = 5f; // À̵¿ ¼Óµµ public float dashDistance = 3f; // ´ë½Ã °Å¸® public float dashCooldown = 1f; // ´ë½Ã ÄðŸÀÓ + public float maxSpeed = 8f; // ÃÖ´ë ¼Óµµ (2~3ÃÊ ÈÄ ÃÖ´ë ¼Óµµ µµ´Þ) + public float accelerationTime = 2f; // 2ÃÊ µ¿¾È °¡¼Ó + private float moveTime = 0f; // À̵¿ÇÑ ½Ã°£ public float dashTime = 0.5f; private bool canDash = true; // ´ë½Ã °¡´É ¿©ºÎ private Vector2 moveDirection = Vector2.zero; // ÇöÀç À̵¿ ¹æÇâ @@ -55,10 +58,22 @@ public class PlayerController : MonoBehaviour // À̵¿ ¹æÇâÀÌ ÀÖÀ» ¶§¸¸ À̵¿ if (isWalking) { - transform.position += (Vector3)(moveDirection.normalized * moveSpeed * Time.deltaTime); - // ¾Ö´Ï¸ÞÀÌ¼Ç À̵¿ ¹æÇâ ¼³Á¤ - animator.SetFloat("moveX", Mathf.Abs(moveDirection.x)); - animator.SetFloat("moveY", moveDirection.y); + moveTime += Time.deltaTime; + // 2ÃÊ ÀÌ»ó À̵¿Çϸé Áï½Ã ¼Óµµ¸¦ maxSpeed·Î Áõ°¡ + float currentSpeed = HandleAcceleration(); + + transform.position += (Vector3)(moveDirection.normalized * currentSpeed * Time.deltaTime); + // A ¶Ç´Â D°¡ ´­¸° »óŶó¸é Side ¾Ö´Ï¸ÞÀ̼ÇÀ» ¿ì¼± Àû¿ë + if (moveDirection.x != 0) + { + animator.SetFloat("moveX", 1); // ¹«Á¶°Ç Side ¾Ö´Ï¸ÞÀÌ¼Ç + animator.SetFloat("moveY", 0); // À§/¾Æ·¡´Â ¹«½Ã + } + else + { + animator.SetFloat("moveX", 0); + animator.SetFloat("moveY", moveDirection.y); + } // ȸÀü ó¸® if (Mathf.Abs(moveDirection.x) > 0) @@ -76,12 +91,25 @@ public class PlayerController : MonoBehaviour else { // À̵¿ÇÏÁö ¾ÊÀ¸¸é Idle »óŸ¦ ¼³Á¤ + moveTime = 0f; animator.SetFloat("moveX", 0); animator.SetFloat("moveY", 0); animator.SetFloat("idleState", idleState); } - } + } + float HandleAcceleration() + { + if (isWalking) + { + moveTime += Time.deltaTime; + if (moveTime >= accelerationTime) + { + return maxSpeed; // 2ÃÊ ÀÌ»ó À̵¿ ½Ã °¡¼Ó + } + } + return moveSpeed; // ±âº» ¼Óµµ + } // ´ë½Ã ó¸® void Dash() {