抛竿动画
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1188,9 +1188,9 @@ AnimatorStateTransition:
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.765625
|
||||
m_TransitionDuration: 0.24158406
|
||||
m_TransitionOffset: 0.0042079114
|
||||
m_ExitTime: 1
|
||||
m_HasExitTime: 1
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,12 +9,7 @@ namespace NBF
|
||||
public float ChargedProgress;
|
||||
|
||||
[Header("抛竿参数")]
|
||||
[SerializeField] private float throwUpAngle = 25f; // 向上抛出的角度(度)
|
||||
[SerializeField] private float throwDuration = 1.5f; // 抛竿飞行时间
|
||||
[SerializeField] private float minThrowPower = 15f;
|
||||
[SerializeField] private float maxThrowPower = 60f;
|
||||
|
||||
private LureThrowTrajectory _trajectoryController;
|
||||
[SerializeField] private float throwUpAngle = 0.7f; // 向上抛出的角度系数,越大抛得越高
|
||||
|
||||
protected override void OnEnter()
|
||||
{
|
||||
@@ -29,17 +24,9 @@ namespace NBF
|
||||
|
||||
Debug.Log($"PlayerThrow ChargedProgress={ChargedProgress}");
|
||||
_nextState = false;
|
||||
// Stage = Phase.Waiting;
|
||||
|
||||
// 初始化轨迹控制器
|
||||
_trajectoryController?.Dispose();
|
||||
_trajectoryController = new LureThrowTrajectory();
|
||||
_trajectoryController.SetPowerRange(minThrowPower, maxThrowPower);
|
||||
}
|
||||
|
||||
protected override void OnExit()
|
||||
{
|
||||
// 清理轨迹控制器
|
||||
_trajectoryController?.Kill();
|
||||
// _owner.Gears.Reel?.Unlock();
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
@@ -47,6 +34,7 @@ namespace NBF
|
||||
CheckStateTimeout(10);
|
||||
if (_nextState)
|
||||
{
|
||||
// return (uint)PlayerState.Fishing;
|
||||
_nextState = false;
|
||||
Player.ChangeState(PlayerState.Fishing);
|
||||
}
|
||||
@@ -64,76 +52,25 @@ namespace NBF
|
||||
UnTakeLine();
|
||||
PlayerView.Unity.ModelAsset.PlayerAnimator.PrepareThrow = false;
|
||||
PlayerView.Unity.ModelAsset.PlayerAnimator.StartThrow = false;
|
||||
|
||||
var rod = GetRod();
|
||||
if (rod != null && rod.Line != null && rod.Line.Lure != null)
|
||||
{
|
||||
var lureTransform = rod.Line.Lure.transform;
|
||||
var lureRigidbody = rod.Line.Lure.RBody;
|
||||
// 使用 ChargedProgress 作为力度系数 (0-1)
|
||||
float throwForce = 20f + ChargedProgress * 100f;
|
||||
|
||||
// 计算抛竿起点(竿尖位置)
|
||||
Vector3 startPos = rod.Asset.lineConnector.position;
|
||||
// 水平向前 + 向上抛出,形成抛物线轨迹
|
||||
Vector3 throwDirection = PlayerView.Unity.FppLook.transform.forward;// + Vector3.up * throwUpAngle;
|
||||
|
||||
// 计算抛竿方向(基于角色朝向 + 向上角度)
|
||||
float radians = throwUpAngle * Mathf.Deg2Rad;
|
||||
Vector3 forward = PlayerView.Unity.transform.forward;
|
||||
Vector3 throwDirection = forward * Mathf.Cos(radians) + Vector3.up * Mathf.Sin(radians);
|
||||
|
||||
// 构建抛竿输入参数
|
||||
var throwInput = new ThrowInput
|
||||
{
|
||||
power = ChargedProgress,
|
||||
lureWeight = 10f, // TODO: 从钓饵配置获取
|
||||
lineDiameter = 0.2f, // TODO: 从线配置获取
|
||||
windDirection = Vector3.zero,
|
||||
windStrength = 0f
|
||||
};
|
||||
|
||||
// 计算轨迹
|
||||
var trajectory = _trajectoryController.CalculateTrajectory(throwInput, startPos, throwDirection);
|
||||
|
||||
// 简化轨迹(优化性能)
|
||||
trajectory = _trajectoryController.SimplifyTrajectory(trajectory, 0.15f);
|
||||
|
||||
// 计算飞行时间(基于轨迹长度)
|
||||
float duration = _trajectoryController.CalculateDuration(trajectory, 0.8f + ChargedProgress * 0.5f);
|
||||
|
||||
// 先将Lure瞬移到起点
|
||||
lureTransform.position = startPos;
|
||||
|
||||
// 执行轨迹动画
|
||||
_trajectoryController.ExecuteThrow(
|
||||
lureTransform,
|
||||
lureRigidbody,
|
||||
trajectory,
|
||||
duration,
|
||||
() =>
|
||||
{
|
||||
// 动画完成,切换状态
|
||||
_nextState = true;
|
||||
}
|
||||
);
|
||||
|
||||
Debug.Log($"抛竿轨迹: 点位数={trajectory.Count}, 飞行时间={duration:F2}s, 落点={trajectory[^1]}");
|
||||
rod.Line.Lure.RBody.AddForce(throwDirection.normalized * throwForce, ForceMode.VelocityChange);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnRodThrownEnd()
|
||||
{
|
||||
Debug.LogError("OnRodThrownEnd");
|
||||
// 状态切换现在由轨迹动画完成回调处理
|
||||
_nextState = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
// 扩展 LureThrowTrajectory 添加 SetPowerRange 方法
|
||||
public partial class LureThrowTrajectory
|
||||
{
|
||||
public void SetPowerRange(float min, float max)
|
||||
{
|
||||
_minThrowPower = min;
|
||||
_maxThrowPower = max;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,4 @@ MonoBehaviour:
|
||||
m_Name: EditorUndoStackPointer
|
||||
m_EditorClassIdentifier: "UMotionEditor.dll::\u0389\u0389\u0389\u0389\u038A\u0389\u0389\u0389\u038A\u038A\u038A\u038A\u038A\u0389\u038A\u038A\u038A\u0389\u038A\u038A\u0389\u0389\u0389\u038A\u038A\u038A\u038A\u038A\u038A\u0389\u038A\u038A\u0389\u038A\u038A\u0389\u038A\u0389\u0389\u0389\u038A\u0389\u0389\u0389\u0389\u0389\u038A"
|
||||
"\u0389\u038A\u0389\u038A\u0389\u038A\u0389\u038A\u038A\u038A\u038A\u0389\u038A\u0389\u038A\u0389\u0389\u038A\u0389\u038A\u0389\u038A\u0389\u038A\u0389\u038A\u0389\u0389\u038A\u0389\u0389\u038A\u0389\u038A\u038A\u0389\u0389\u038A\u038A\u0389\u0389\u038A\u0389\u038A\u038A\u0389\u038A": 1.29p03
|
||||
"\u038A\u038A\u0389\u038A\u038A\u0389\u0389\u0389\u038A\u0389\u038A\u038A\u038A\u0389\u038A\u0389\u0389\u0389\u038A\u0389\u038A\u0389\u038A\u038A\u038A\u038A\u038A\u0389\u0389\u0389\u0389\u0389\u038A\u038A\u0389\u038A\u0389\u0389\u0389\u0389\u038A\u038A\u0389\u038A\u0389\u0389\u0389": 42
|
||||
"\u038A\u038A\u0389\u038A\u038A\u0389\u0389\u0389\u038A\u0389\u038A\u038A\u038A\u0389\u038A\u0389\u0389\u0389\u038A\u0389\u038A\u0389\u038A\u038A\u038A\u038A\u038A\u0389\u0389\u0389\u0389\u0389\u038A\u038A\u0389\u038A\u0389\u0389\u0389\u0389\u038A\u038A\u0389\u038A\u0389\u0389\u0389": 3
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user