diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-01-31 20:14:48 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-01-31 20:14:48 +0800 |
| commit | 74a4f421b436b5950e52660ba7d6ebc53a818fa5 (patch) | |
| tree | 9841fb6655fee855ba581768872de2deacf57f38 /Assets/Scripts/PlayerMovement.cs | |
| parent | 38e3e1fa64334f9cfd2f35e21439b93f525bf1b4 (diff) | |
Diffstat (limited to 'Assets/Scripts/PlayerMovement.cs')
| -rw-r--r-- | Assets/Scripts/PlayerMovement.cs | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index 90252b3..add03ba 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -1,15 +1,21 @@ -using System; using UnityEngine; [RequireComponent(typeof(PlayerControl))] [RequireComponent(typeof(Rigidbody))] public class PlayerMovement : MonoBehaviour { - public float movementSpeed; - public float movementSpeedOnGrabbing; + private static readonly float BoostAccel = 10; + public float movementSpeed = 5; + public float movementSpeedOnGrabbing = 3; + public float boostFalloffLerp = 0.025f; + private PlayerControl _playerControl; private Rigidbody _rigidbody; + + private float _currentBoost; + + private bool CanBoost => _currentBoost <= 0.1f; private void Awake() { @@ -17,15 +23,25 @@ public class PlayerMovement : MonoBehaviour _rigidbody = GetComponent<Rigidbody>(); } + private void Update() + { + if (_playerControl.boosting && CanBoost) + { + _currentBoost = BoostAccel; + } + } + private void FixedUpdate() { FixedUpdateMovement(); + + FixedUpdateBoostFalloff(); } private void FixedUpdateMovement() { var velocity = _rigidbody.linearVelocity; - var speed = _playerControl.grabbing ? movementSpeedOnGrabbing : movementSpeed; + var speed = _playerControl.grabbing ? movementSpeedOnGrabbing : movementSpeed + _currentBoost; var direction = new Vector3( _playerControl.movementHorizontal, 0, @@ -34,4 +50,9 @@ public class PlayerMovement : MonoBehaviour var playerVelocity = speed * direction + velocity.y * Vector3.up; _rigidbody.linearVelocity = playerVelocity; } + + private void FixedUpdateBoostFalloff() + { + _currentBoost = Mathf.Lerp(_currentBoost, 0, boostFalloffLerp); + } } |
