This commit is contained in:
SoulliesOfficial
2026-01-03 18:19:39 -05:00
parent 3bcd7c1cf8
commit 33b1795c1f
7387 changed files with 2762819 additions and 716926 deletions

View File

@@ -25,16 +25,17 @@ namespace Cielonos.MainGame.Characters
{
Vector3 cameraForward = player.viewSc.playerCamera.transform.forward.Flatten();
player.landMovementSc.TurnToDirection(inputDirection);
Vector3 dashCameraRotation = CalculateDashAngles(inputDirection, cameraForward);
Vector3 playerForward = player.transform.forward.Flatten();
Vector3 dashCameraRotation = CalculateDashAngles(playerForward, cameraForward);
player.feedbackSc["Dash"].feedback.GetFeedbackOfType<MMF_CinemachineRotation>().RotationAmplitude = dashCameraRotation;
player.feedbackSc["Dash"].feedback.GetFeedbackOfType<MMF_RadialBlur>().TargetCenter = player.GetNormalizedScreenPosition();
fullBodyFuncAnimSm.Play("Dash");
};
player.operationSc.OnDodge += delegate
{
Vector3 dodgeDirection = Vector3.back;
Vector3 playerBackward = -player.transform.forward.Flatten();
Vector3 cameraForward = player.viewSc.playerCamera.transform.forward.Flatten();
Vector3 dodgeCameraRotation = CalculateDashAngles(dodgeDirection, cameraForward);
Vector3 dodgeCameraRotation = CalculateDashAngles(playerBackward, cameraForward);
player.feedbackSc["Dodge"].feedback.GetFeedbackOfType<MMF_CinemachineRotation>().RotationAmplitude = dodgeCameraRotation;
player.feedbackSc["Dodge"].feedback.GetFeedbackOfType<MMF_RadialBlur>().TargetCenter = player.GetNormalizedScreenPosition();
fullBodyFuncAnimSm.Play("Dodge");
@@ -132,27 +133,39 @@ namespace Cielonos.MainGame.Characters
public partial class PlayerAnimationSubcontroller
{
/// <summary>
/// 计算冲刺时的机倾斜和俯仰
/// 计算冲刺时的摄像机倾斜角度
/// </summary>
/// <param name="dashDir">世界空间的冲刺向量 (如 Vector3.forward)</param>
/// <param name="camForwardNoY">相机的前方 (y被设为0并归一化)</param>
/// <returns>x为Pitch(俯仰), z为Dutch(侧倾)</returns>
public Vector3 CalculateDashAngles(Vector3 dashDir, Vector3 camForwardNoY)
/// <param name="dashDir">冲刺输入的平整化方向 (y=0, normalized)</param>
/// <param name="camFwd">摄像机的平整化前方 (y=0, normalized)</param>
/// <returns>Vector3(Pitch角度, 0, Roll角度)</returns>
public Vector3 CalculateDashAngles(Vector3 dashDir, Vector3 camFwd)
{
// 1. 获取相机的右方
Vector3 camRight = Vector3.Cross(Vector3.up, camForwardNoY);
// 1. 确保输入向量是归一化的(以防万一)
Vector3 d = dashDir.normalized;
Vector3 f = camFwd.normalized;
// 2. 将冲刺方向投影到相机的 前/后 和 左/右 轴上
float forwardDot = Vector3.Dot(dashDir, camForwardNoY); // 1为前-1为后
float rightDot = Vector3.Dot(dashDir, camRight); // 1为右-1为左
// 2. 通过叉乘获取摄像机的水平右方向 (camRight)
// 在左手坐标系UnityUp x Forward = Right
Vector3 r = Vector3.Cross(Vector3.up, f);
// 3. 计算目标侧倾值
float targetDutch = forwardDot * 1f;
// 3. 计算投影权重 (范围在 -1 到 1 之间)
// forwardWeight: 1表示完全同向-1表示完全反向
float forwardWeight = Vector3.Dot(d, f);
// sideWeight: 1表示向右冲-1表示向左冲
float sideWeight = Vector3.Dot(d, r);
// 4. 计算目标俯仰值(注意取反,使得向前冲刺时相机向下俯仰)
float targetPitch = -rightDot * 2.0f;
return new Vector3(targetPitch, 0, targetDutch);
// 4. 定义倾斜强度系数 (控制在 1.5度 左右)
const float tiltIntensity = 1.5f;
// 5. 计算最终角度
// x 轴旋转 (Pitch):正值向下倾斜(向前冲),负值向上倾斜(向后退)
float pitch = forwardWeight * tiltIntensity;
// z 轴旋转 (Dutch/Roll)
// 注意:向右冲时(sideWeight=1),通常相机向左倾斜(z为负值)更有动感
float roll = -sideWeight * tiltIntensity;
return new Vector3(pitch, 0, roll);
}
}
}