From 9e19146e35fadaca23505b10242ac1940480de3c Mon Sep 17 00:00:00 2001 From: MelekTaus Moribundus Date: Mon, 22 Jun 2026 21:46:57 +0200 Subject: [PATCH] Add hold-to-sprint with dedicated speed multiplier Co-Authored-By: Claude Opus 4.8 --- Assets/Scripts/PlayerCharacterController.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/PlayerCharacterController.cs b/Assets/Scripts/PlayerCharacterController.cs index 8ded7ce..0932255 100644 --- a/Assets/Scripts/PlayerCharacterController.cs +++ b/Assets/Scripts/PlayerCharacterController.cs @@ -32,6 +32,9 @@ public class PlayerCharacterController : MonoBehaviour [Tooltip("Horizontal movement speed (units/second).")] public float moveSpeed = 4f; + [Tooltip("Speed multiplier applied to ground movement while the sprint key (Left Shift) is held.")] + public float sprintSpeedMultiplier = 1.8f; + [Tooltip("Interpret WASD relative to the camera (off = world X/Z axes).")] public bool cameraRelative = true; @@ -165,6 +168,7 @@ public class PlayerCharacterController : MonoBehaviour { float h = 0f, v = 0f; bool jumpPressed = false; + bool sprinting = false; // Skip input when control is disabled (e.g. paint mode); gravity and // grounding below still run so the player stays planted. @@ -179,11 +183,13 @@ public class PlayerCharacterController : MonoBehaviour if (keyboard.sKey.isPressed) v -= 1f; if (keyboard.wKey.isPressed) v += 1f; jumpPressed = keyboard.spaceKey.wasPressedThisFrame; + sprinting = keyboard.leftShiftKey.isPressed; } #else h = Input.GetAxisRaw("Horizontal"); v = Input.GetAxisRaw("Vertical"); jumpPressed = Input.GetButtonDown("Jump"); + sprinting = Input.GetKey(KeyCode.LeftShift); #endif } @@ -265,7 +271,8 @@ public class PlayerCharacterController : MonoBehaviour _slideSpeed = 0f; } - Vector3 velocity = moveDir * moveSpeed + slideVelocity + Vector3.up * _verticalVelocity; + float currentSpeed = sprinting ? moveSpeed * sprintSpeedMultiplier : moveSpeed; + Vector3 velocity = moveDir * currentSpeed + slideVelocity + Vector3.up * _verticalVelocity; // Move fires OnControllerColliderHit, which refills the ground normal; // fall back to "up" if nothing was hit.