From 905b0c36301e96feabac6cd3e2a51252b075ef66 Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Fri, 22 May 2026 13:23:04 +0800 Subject: 改了个RootMotion的代码,并且我要谴责罗师傅的单例时机不对 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/AnimatorHandler.cs | 6 +++++- Assets/Scripts/InputHandler.cs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'Assets/Scripts') diff --git a/Assets/Scripts/AnimatorHandler.cs b/Assets/Scripts/AnimatorHandler.cs index deae0ac..f285dca 100644 --- a/Assets/Scripts/AnimatorHandler.cs +++ b/Assets/Scripts/AnimatorHandler.cs @@ -11,6 +11,9 @@ namespace DS /// public class AnimatorHandler : MonoBehaviour { + [Header("绑定")] + public Transform rootMotionRotation; // 将他妈的模型旋转绑定到 RootMotion + [Header("组件引用")] public PlayerLocomotion playerLocomotion; // 玩家移动控制器引用,用于传递根运动数据 public Animator animator; // 动画器组件引用 @@ -139,7 +142,7 @@ namespace DS { // 获取当前帧的根运动位移向量 var rootMotion = GetRootMotion(); - + // 输出调试日志,用于查看根运动数据 Debug.Log(rootMotion); @@ -174,6 +177,7 @@ namespace DS // 将 animator.velocity(动画驱动的速度向量)投影到法线定义的平面上 // Vector3.ProjectOnPlane 会去除向量中沿法线方向的分量 // 这样只保留水平方向的位移,避免 Y 轴上的微小波动影响角色位置 + // return Vector3.ProjectOnPlane(animator.velocity, normalVector); return Vector3.ProjectOnPlane(animator.velocity, normalVector); } } diff --git a/Assets/Scripts/InputHandler.cs b/Assets/Scripts/InputHandler.cs index 4d0bba1..6da34f0 100644 --- a/Assets/Scripts/InputHandler.cs +++ b/Assets/Scripts/InputHandler.cs @@ -37,7 +37,7 @@ namespace DS // ===== Unity 生命周期方法 ===== - private void Awake() + private void Start() { // 获取相机处理器的单例引用,用于在 FixedUpdate 中驱动相机跟随与旋转 _cameraHandler = CameraHandler.singleton; -- cgit