aboutsummaryrefslogtreecommitdiff
path: root/Assets
diff options
context:
space:
mode:
authorSmallFox <2806143047@qq.com>2026-06-02 19:38:24 +0800
committerSmallFox <2806143047@qq.com>2026-06-02 19:38:24 +0800
commit8537159642af167feae6f64d0614252f6016a54e (patch)
tree08a37d50ef9c808a7c0df1799e03add76dec5bdc /Assets
parent37618e6e39aa58130f4237995753bcf202da136a (diff)
冲刺
Diffstat (limited to 'Assets')
-rw-r--r--Assets/Scripts/AnimatorHandler.cs8
-rw-r--r--Assets/Scripts/InputHandler.cs15
-rw-r--r--Assets/Scripts/PlayerLocomotion.cs26
-rw-r--r--Assets/Scripts/PlayerManager.cs1
4 files changed, 44 insertions, 6 deletions
diff --git a/Assets/Scripts/AnimatorHandler.cs b/Assets/Scripts/AnimatorHandler.cs
index 775ffc4..157b78f 100644
--- a/Assets/Scripts/AnimatorHandler.cs
+++ b/Assets/Scripts/AnimatorHandler.cs
@@ -55,7 +55,7 @@ namespace DS
/// </summary>
/// <param name="verticalMovement">垂直方向的移动输入(前进/后退),范围 -1 ~ 1</param>
/// <param name="horizontalMovement">水平方向的移动输入(左移/右移),范围 -1 ~ 1</param>
- public void UpdateAnimatorValues(float verticalMovement, float horizontalMovement)
+ public void UpdateAnimatorValues(float verticalMovement, float horizontalMovement,bool isSprinting)
{
#region Vertical — 垂直方向(前进/后退)的动画参数处理
@@ -114,6 +114,12 @@ namespace DS
}
#endregion
+
+ if (isSprinting)
+ {
+ v = 2;
+ h = horizontalMovement;
+ }
// 将计算后的参数值设置到 Animator 中
// 第三个参数 dampTime 为 0.1f,表示在 0.1 秒内平滑过渡到目标值
diff --git a/Assets/Scripts/InputHandler.cs b/Assets/Scripts/InputHandler.cs
index 8144da7..9f57c20 100644
--- a/Assets/Scripts/InputHandler.cs
+++ b/Assets/Scripts/InputHandler.cs
@@ -30,6 +30,8 @@ namespace DS
public bool b_Input;
public bool rollFlag;
+ public bool sprintFlag;
+ public float rollInputTimer;
public bool isInteracting;
[Header("其他操作输入")]
@@ -136,7 +138,18 @@ namespace DS
b_Input = _inputActions.PlayerActions.Roll.phase == UnityEngine.InputSystem.InputActionPhase.Performed;
if (b_Input)
{
- rollFlag = true;
+ rollInputTimer += delta;
+ sprintFlag = true;
+ }
+ else
+ {
+ if (rollInputTimer > 0 && rollInputTimer < 0.5)
+ {
+ rollFlag = true;
+ sprintFlag = false;
+ }
+
+ rollInputTimer = 0;
}
}
}
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. 更新翻滚参数
diff --git a/Assets/Scripts/PlayerManager.cs b/Assets/Scripts/PlayerManager.cs
index 1acd8e4..e80c0a2 100644
--- a/Assets/Scripts/PlayerManager.cs
+++ b/Assets/Scripts/PlayerManager.cs
@@ -19,5 +19,6 @@ public class PlayerManager : MonoBehaviour
{
_inputHandler.isInteracting = _animator.GetBool("isInteracting");
_inputHandler.rollFlag = false;
+ _inputHandler.sprintFlag = false;
}
}