From 14a01125a885ee4dbd2de6c1f57bbcd12ca12110 Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Sat, 30 May 2026 17:05:13 +0800 Subject: 完成动画中翻滚的绑定 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/AnimatorHandler.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'Assets/Scripts/AnimatorHandler.cs') diff --git a/Assets/Scripts/AnimatorHandler.cs b/Assets/Scripts/AnimatorHandler.cs index de1af4c..665a1ca 100644 --- a/Assets/Scripts/AnimatorHandler.cs +++ b/Assets/Scripts/AnimatorHandler.cs @@ -12,7 +12,8 @@ namespace DS public class AnimatorHandler : MonoBehaviour { [Header("绑定")] - public Transform rootMotionRotation; // 将他妈的模型旋转绑定到 RootMotion + public Transform rootMotionRotation; // 将模型旋转绑定到 RootMotion + public InputHandler inputHandler; [Header("组件引用")] public PlayerLocomotion playerLocomotion; // 玩家移动控制器引用,用于传递根运动数据 @@ -21,6 +22,7 @@ namespace DS [Header("动画参数哈希")] private int _vertical; // "Vertical" 动画参数的哈希值,用于高效设置动画参数 private int _horizontal; // "Horizontal" 动画参数的哈希值 + private int _roll; // "Roll" 动画参数的哈希值 [Header("旋转状态")] public bool canRotate; // 是否允许角色旋转,在动画事件中控制 @@ -38,6 +40,7 @@ namespace DS // 这样在 SetFloat 时使用哈希值比使用字符串更高效 _vertical = Animator.StringToHash("Vertical"); _horizontal = Animator.StringToHash("Horizontal"); + _roll = Animator.StringToHash("Roll"); } /// @@ -106,7 +109,7 @@ namespace DS } #endregion - + // 将计算后的参数值设置到 Animator 中 // 第三个参数 dampTime 为 0.1f,表示在 0.1 秒内平滑过渡到目标值 // 第四个参数 deltaTime 用于确保平滑速度与帧率无关 @@ -114,6 +117,14 @@ namespace DS animator.SetFloat(_horizontal, h, 0.1f, Time.deltaTime); } + /// + /// 触发动画的翻滚 + /// + public void TriggerRoll() + { + animator.SetTrigger(_roll); + } + /// /// 动画事件回调 - 允许角色在动画的特定帧开始旋转。 /// 通常在动画的某个时间点(如转身动画的起始帧)由动画事件调用。 -- cgit