diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-05-30 17:05:13 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-05-30 17:05:13 +0800 |
| commit | 14a01125a885ee4dbd2de6c1f57bbcd12ca12110 (patch) | |
| tree | 0d2ee7539c26a495132c9b7d8c1c4e5d87d7a19b /Assets/Scripts/AnimatorHandler.cs | |
| parent | f33ad8a7aa7359653fd2d98a8645e01087637980 (diff) | |
完成动画中翻滚的绑定
Diffstat (limited to 'Assets/Scripts/AnimatorHandler.cs')
| -rw-r--r-- | Assets/Scripts/AnimatorHandler.cs | 15 |
1 files changed, 13 insertions, 2 deletions
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"); } /// <summary> @@ -106,7 +109,7 @@ namespace DS } #endregion - + // 将计算后的参数值设置到 Animator 中 // 第三个参数 dampTime 为 0.1f,表示在 0.1 秒内平滑过渡到目标值 // 第四个参数 deltaTime 用于确保平滑速度与帧率无关 @@ -115,6 +118,14 @@ namespace DS } /// <summary> + /// 触发动画的翻滚 + /// </summary> + public void TriggerRoll() + { + animator.SetTrigger(_roll); + } + + /// <summary> /// 动画事件回调 - 允许角色在动画的特定帧开始旋转。 /// 通常在动画的某个时间点(如转身动画的起始帧)由动画事件调用。 /// </summary> |
