aboutsummaryrefslogtreecommitdiff
path: root/Assets
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2026-05-30 17:05:13 +0800
committerWeicao-CatilGrass <1992414357@qq.com>2026-05-30 17:05:13 +0800
commit14a01125a885ee4dbd2de6c1f57bbcd12ca12110 (patch)
tree0d2ee7539c26a495132c9b7d8c1c4e5d87d7a19b /Assets
parentf33ad8a7aa7359653fd2d98a8645e01087637980 (diff)
完成动画中翻滚的绑定
Diffstat (limited to 'Assets')
-rw-r--r--Assets/Art/Animations/Falling To Roll.fbx.meta2
-rw-r--r--Assets/Art/Animator/Humanoid.controller14
-rw-r--r--Assets/Scenes/SampleScene.unity2
-rw-r--r--Assets/Scripts/AnimatorHandler.cs15
-rw-r--r--Assets/Scripts/InputHandler.cs8
-rw-r--r--Assets/Scripts/InputSystem/PlayerControls.cs30
-rw-r--r--Assets/Scripts/InputSystem/PlayerControls.inputactions20
-rw-r--r--Assets/Scripts/PlayerLocomotion.cs11
8 files changed, 90 insertions, 12 deletions
diff --git a/Assets/Art/Animations/Falling To Roll.fbx.meta b/Assets/Art/Animations/Falling To Roll.fbx.meta
index 2b85016..48e6198 100644
--- a/Assets/Art/Animations/Falling To Roll.fbx.meta
+++ b/Assets/Art/Animations/Falling To Roll.fbx.meta
@@ -40,7 +40,7 @@ ModelImporter:
lastFrame: 45
wrapMode: 0
orientationOffsetY: 0
- level: 0
+ level: -0.25
cycleOffset: 0
loop: 0
hasAdditiveReferencePose: 0
diff --git a/Assets/Art/Animator/Humanoid.controller b/Assets/Art/Animator/Humanoid.controller
index 3db58dc..f1f9a59 100644
--- a/Assets/Art/Animator/Humanoid.controller
+++ b/Assets/Art/Animator/Humanoid.controller
@@ -14,9 +14,9 @@ AnimatorStateTransition:
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
- m_TransitionDuration: 0.25
+ m_TransitionDuration: 0.5
m_TransitionOffset: 0
- m_ExitTime: 0.8333334
+ m_ExitTime: 0.5
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
@@ -31,7 +31,7 @@ AnimatorStateTransition:
m_Name:
m_Conditions:
- m_ConditionMode: 1
- m_ConditionEvent: Debug_Roll
+ m_ConditionEvent: Roll
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 3051980819593247121}
@@ -39,7 +39,7 @@ AnimatorStateTransition:
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
- m_TransitionDuration: 0.25
+ m_TransitionDuration: 0.5
m_TransitionOffset: 0
m_ExitTime: 0.7494432
m_HasExitTime: 0
@@ -90,7 +90,7 @@ AnimatorController:
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- - m_Name: Debug_Roll
+ - m_Name: Roll
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
@@ -155,7 +155,7 @@ AnimatorState:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
- m_Name: mixamo_com
+ m_Name: Roll
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
@@ -215,7 +215,7 @@ AnimatorStateMachine:
m_ChildStates:
- serializedVersion: 1
m_State: {fileID: 7601682898943563198}
- m_Position: {x: 350, y: 110, z: 0}
+ m_Position: {x: 360, y: 120, z: 0}
- serializedVersion: 1
m_State: {fileID: 3051980819593247121}
m_Position: {x: 360, y: 10, z: 0}
diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity
index 492ded0..08b499d 100644
--- a/Assets/Scenes/SampleScene.unity
+++ b/Assets/Scenes/SampleScene.unity
@@ -538,7 +538,7 @@ Camera:
height: 1
near clip plane: 0.3
far clip plane: 1000
- field of view: 40
+ field of view: 75
orthographic: 0
orthographic size: 5
m_Depth: -1
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>
diff --git a/Assets/Scripts/InputHandler.cs b/Assets/Scripts/InputHandler.cs
index 6da34f0..9d2ab72 100644
--- a/Assets/Scripts/InputHandler.cs
+++ b/Assets/Scripts/InputHandler.cs
@@ -28,6 +28,10 @@ namespace DS
[Tooltip("鼠标或右摇杆的垂直移动增量")]
public float mouseY;
+ [Header("其他操作输入")]
+ [Tooltip("翻滚是否触发")]
+ public bool rollTriggered;
+
// ===== 私有引用与输入缓存 =====
private PlayerControls _inputActions; // 新输入系统生成的 PlayerControls 实例
private CameraHandler _cameraHandler; // 相机处理器单例引用
@@ -76,6 +80,10 @@ namespace DS
// 当视角控制被触发(鼠标移动/右摇杆)时,将输入值存入 _cameraInput
_inputActions.PlayerMovement.Camera.performed +=
ctx => _cameraInput = ctx.ReadValue<Vector2>();
+
+ // 增加翻滚行为
+ _inputActions.PlayerMovement.Roll.performed +=
+ ctx => rollTriggered = ctx.ReadValueAsButton();
}
// 启用输入动作监听
diff --git a/Assets/Scripts/InputSystem/PlayerControls.cs b/Assets/Scripts/InputSystem/PlayerControls.cs
index c76f6ba..c77acf2 100644
--- a/Assets/Scripts/InputSystem/PlayerControls.cs
+++ b/Assets/Scripts/InputSystem/PlayerControls.cs
@@ -44,6 +44,15 @@ public partial class @PlayerControls: IInputActionCollection2, IDisposable
""processors"": """",
""interactions"": """",
""initialStateCheck"": true
+ },
+ {
+ ""name"": ""Roll"",
+ ""type"": ""Button"",
+ ""id"": ""5e423815-95ec-43c1-9718-224f86c8f24e"",
+ ""expectedControlType"": ""Button"",
+ ""processors"": """",
+ ""interactions"": """",
+ ""initialStateCheck"": false
}
],
""bindings"": [
@@ -123,6 +132,17 @@ public partial class @PlayerControls: IInputActionCollection2, IDisposable
""action"": ""Camera"",
""isComposite"": false,
""isPartOfComposite"": false
+ },
+ {
+ ""name"": """",
+ ""id"": ""4690e573-c6d7-4c20-bbee-ba5d11ca8a18"",
+ ""path"": ""<Keyboard>/space"",
+ ""interactions"": """",
+ ""processors"": """",
+ ""groups"": """",
+ ""action"": ""Roll"",
+ ""isComposite"": false,
+ ""isPartOfComposite"": false
}
]
}
@@ -133,6 +153,7 @@ public partial class @PlayerControls: IInputActionCollection2, IDisposable
m_PlayerMovement = asset.FindActionMap("Player Movement", throwIfNotFound: true);
m_PlayerMovement_Movement = m_PlayerMovement.FindAction("Movement", throwIfNotFound: true);
m_PlayerMovement_Camera = m_PlayerMovement.FindAction("Camera", throwIfNotFound: true);
+ m_PlayerMovement_Roll = m_PlayerMovement.FindAction("Roll", throwIfNotFound: true);
}
public void Dispose()
@@ -196,12 +217,14 @@ public partial class @PlayerControls: IInputActionCollection2, IDisposable
private List<IPlayerMovementActions> m_PlayerMovementActionsCallbackInterfaces = new List<IPlayerMovementActions>();
private readonly InputAction m_PlayerMovement_Movement;
private readonly InputAction m_PlayerMovement_Camera;
+ private readonly InputAction m_PlayerMovement_Roll;
public struct PlayerMovementActions
{
private @PlayerControls m_Wrapper;
public PlayerMovementActions(@PlayerControls wrapper) { m_Wrapper = wrapper; }
public InputAction @Movement => m_Wrapper.m_PlayerMovement_Movement;
public InputAction @Camera => m_Wrapper.m_PlayerMovement_Camera;
+ public InputAction @Roll => m_Wrapper.m_PlayerMovement_Roll;
public InputActionMap Get() { return m_Wrapper.m_PlayerMovement; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
@@ -217,6 +240,9 @@ public partial class @PlayerControls: IInputActionCollection2, IDisposable
@Camera.started += instance.OnCamera;
@Camera.performed += instance.OnCamera;
@Camera.canceled += instance.OnCamera;
+ @Roll.started += instance.OnRoll;
+ @Roll.performed += instance.OnRoll;
+ @Roll.canceled += instance.OnRoll;
}
private void UnregisterCallbacks(IPlayerMovementActions instance)
@@ -227,6 +253,9 @@ public partial class @PlayerControls: IInputActionCollection2, IDisposable
@Camera.started -= instance.OnCamera;
@Camera.performed -= instance.OnCamera;
@Camera.canceled -= instance.OnCamera;
+ @Roll.started -= instance.OnRoll;
+ @Roll.performed -= instance.OnRoll;
+ @Roll.canceled -= instance.OnRoll;
}
public void RemoveCallbacks(IPlayerMovementActions instance)
@@ -248,5 +277,6 @@ public partial class @PlayerControls: IInputActionCollection2, IDisposable
{
void OnMovement(InputAction.CallbackContext context);
void OnCamera(InputAction.CallbackContext context);
+ void OnRoll(InputAction.CallbackContext context);
}
}
diff --git a/Assets/Scripts/InputSystem/PlayerControls.inputactions b/Assets/Scripts/InputSystem/PlayerControls.inputactions
index e71a5c9..f3edee9 100644
--- a/Assets/Scripts/InputSystem/PlayerControls.inputactions
+++ b/Assets/Scripts/InputSystem/PlayerControls.inputactions
@@ -22,6 +22,15 @@
"processors": "",
"interactions": "",
"initialStateCheck": true
+ },
+ {
+ "name": "Roll",
+ "type": "Button",
+ "id": "5e423815-95ec-43c1-9718-224f86c8f24e",
+ "expectedControlType": "Button",
+ "processors": "",
+ "interactions": "",
+ "initialStateCheck": false
}
],
"bindings": [
@@ -101,6 +110,17 @@
"action": "Camera",
"isComposite": false,
"isPartOfComposite": false
+ },
+ {
+ "name": "",
+ "id": "4690e573-c6d7-4c20-bbee-ba5d11ca8a18",
+ "path": "<Keyboard>/space",
+ "interactions": "",
+ "processors": "",
+ "groups": "",
+ "action": "Roll",
+ "isComposite": false,
+ "isPartOfComposite": false
}
]
}
diff --git a/Assets/Scripts/PlayerLocomotion.cs b/Assets/Scripts/PlayerLocomotion.cs
index 8b77c06..61eef1f 100644
--- a/Assets/Scripts/PlayerLocomotion.cs
+++ b/Assets/Scripts/PlayerLocomotion.cs
@@ -167,7 +167,16 @@ namespace DS
// ----------------------------------------------------------
// 将玩家的移动量(0~1)传递给 Animator,用于混合行走/奔跑动画
animatorHandler.UpdateAnimatorValues(_inputHandler.moveAmount, 0);
-
+
+ // ----------------------------------------------------------
+ // 5. 更新翻滚参数
+ // ----------------------------------------------------------
+ if (_inputHandler.rollTriggered)
+ {
+ animatorHandler.TriggerRoll();
+ _inputHandler.rollTriggered = false;
+ }
+
// ----------------------------------------------------------
// 5. 处理旋转(仅在允许旋转时执行)
// ----------------------------------------------------------