diff options
Diffstat (limited to 'Assets/Scripts/PlayerLocomotion.cs')
| -rw-r--r-- | Assets/Scripts/PlayerLocomotion.cs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/Assets/Scripts/PlayerLocomotion.cs b/Assets/Scripts/PlayerLocomotion.cs index 5952325..e94099b 100644 --- a/Assets/Scripts/PlayerLocomotion.cs +++ b/Assets/Scripts/PlayerLocomotion.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; using Unity.Mathematics; +using Unity.VisualScripting; using UnityEngine; namespace DS @@ -73,14 +74,17 @@ namespace DS private Vector3 _moveDirection; // 计算出的移动方向向量 private Vector3 _normalVector; // 地面法线向量(用于投影移动方向到地面) private Vector3 _targetPosition; // 目标位置(当前未使用,保留备用) - + // ============================================================ // 参数配置 // ============================================================ [Header("Stats")] [SerializeField] private float movementSpeed = 5; // 移动速度(单位:米/秒) + [SerializeField] private float sprintSpeed = 5; //冲刺速度 [SerializeField] private float rotationSpeed = 10; // 旋转速度(单位:度/秒,实际用于 Slerp 插值) + public bool isSprinting; + // ============================================================ // 初始化 // ============================================================ @@ -111,6 +115,8 @@ namespace DS private void Update() { float delta = Time.deltaTime; // 获取帧时间 + + isSprinting = _inputHandler.b_Input; UpdateCharacterMovement(delta); HandleRollingAndSpringting(delta); } @@ -173,7 +179,10 @@ namespace DS // ============================================================ private void UpdateCharacterMovement(float delta) { - // 处理输入(读取水平/垂直输入值) + if (_inputHandler.rollFlag) + return; + + // 处理输入(读取水平/垂直输入值) _inputHandler.TickInput(delta); // ---------------------------------------------------------- @@ -192,7 +201,16 @@ namespace DS // 2. 应用移动速度 // ---------------------------------------------------------- float speed = movementSpeed; - _moveDirection *= speed; // 现在 _moveDirection 是速度向量(单位:米/秒) + if (_inputHandler.sprintFlag) + { + speed = sprintSpeed; + isSprinting = true; + _moveDirection *= speed; + } + else + { + _moveDirection *= speed; // 现在 _moveDirection 是速度向量(单位:米/秒) + } // ---------------------------------------------------------- // 3. 混合根运动与程序化移动 @@ -214,7 +232,7 @@ namespace DS // 4. 更新动画参数 // ---------------------------------------------------------- // 将玩家的移动量(0~1)传递给 Animator,用于混合行走/奔跑动画 - animatorHandler.UpdateAnimatorValues(_inputHandler.moveAmount, 0); + animatorHandler.UpdateAnimatorValues(_inputHandler.moveAmount, 0,isSprinting); // ---------------------------------------------------------- // 5. 更新翻滚参数 |
