diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-05-22 12:14:00 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-05-22 12:14:00 +0800 |
| commit | 9045525044dd1ab38a559598bea54858f4050c49 (patch) | |
| tree | 2dc94de7ee2eedadf5b5509bbfe211fab36fb284 /Assets/Scripts/AnimatorHandler.cs | |
| parent | 11d02a4cc3ce2d1df6dbfc9ce33e0d8649109382 (diff) | |
增加使用RootMotion驱动的角色移动
Diffstat (limited to 'Assets/Scripts/AnimatorHandler.cs')
| -rw-r--r-- | Assets/Scripts/AnimatorHandler.cs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Assets/Scripts/AnimatorHandler.cs b/Assets/Scripts/AnimatorHandler.cs index d95d12b..b71c573 100644 --- a/Assets/Scripts/AnimatorHandler.cs +++ b/Assets/Scripts/AnimatorHandler.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -6,6 +7,7 @@ namespace DS { public class AnimatorHandler : MonoBehaviour { + public PlayerLocomotion playerLocomotion; public Animator animator; private int _vertical; private int _horizontal; @@ -87,6 +89,20 @@ namespace DS { canRotate = false; } + + private void OnAnimatorMove() + { + Debug.Log(animator.velocity); + playerLocomotion.rootMotion = animator.velocity; + } + + private void OnDrawGizmos() + { + // 我们先假定 地板永远是朝上的 + var normalVector = Vector3.up; + Vector3 rootMotionProjected = Vector3.ProjectOnPlane(animator.velocity, normalVector); + Gizmos.DrawLine(transform.position, transform.position + rootMotionProjected * 2f); + } } } |
