From 9045525044dd1ab38a559598bea54858f4050c49 Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Fri, 22 May 2026 12:14:00 +0800 Subject: 增加使用RootMotion驱动的角色移动 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/AnimatorHandler.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Assets/Scripts/AnimatorHandler.cs') 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); + } } } -- cgit