抛竿运动轨迹修改

This commit is contained in:
2026-03-25 22:43:47 +08:00
parent 59fa39d662
commit e19070a963
17 changed files with 99 additions and 301 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using KINEMATION.MagicBlend.Runtime;
using RootMotion.FinalIK;
using UnityEngine;
@@ -11,7 +11,7 @@ namespace NBF
public PlayerIK IK { get; private set; }
public PlayerAnimator PlayerAnimator { get; private set; }
public MagicBlending MagicBlending { get; private set; }
public PlayerDebug PlayerDebug { get; private set; }
public Transform NeckTransform;
public LookAtIK LookIk;
@@ -43,6 +43,7 @@ namespace NBF
MagicBlending = GetComponent<MagicBlending>();
IK = GetComponent<PlayerIK>();
PlayerAnimator = GetComponent<PlayerAnimator>();
PlayerDebug = GetComponent<PlayerDebug>();
}
public void SetPlayer(Transform FppLook)

View File

@@ -70,6 +70,8 @@ namespace NBF
/// </summary>
public PlayerItem HandItem => Items.GetValueOrDefault(HandItemId);
public List<Vector3> TrajectoryPoints = new List<Vector3>();
#region
public void InitPlayer(MapUnitInfo unitInfo)

View File

@@ -0,0 +1,26 @@
using System;
using UnityEngine;
namespace NBF
{
public class PlayerDebug : PlayerMonoBehaviour
{
private void Update()
{
DrawLastTrajectory();
}
private void DrawLastTrajectory()
{
if (Player == null) return;
for (int i = 1; i < Player.TrajectoryPoints.Count; i++)
{
Debug.DrawLine(Player.TrajectoryPoints[i - 1], Player.TrajectoryPoints[i], Color.yellow);
}
// Debug.DrawRay(Player.TrajectoryPoints[Player.TrajectoryPoints.Count], Vector3.up * 0.3f, Color.cyan);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0fe64f6594c24eef9fbaf147754871f8
timeCreated: 1774445468

View File

@@ -4,6 +4,7 @@ namespace NBF
{
public interface IPlayerThrowAnimation
{
Player Player { get; set; }
bool IsPlaying { get; }
void Play(ThrowAnimationRequest request);
void Tick(float deltaTime);
@@ -13,6 +14,7 @@ namespace NBF
public struct ThrowAnimationRequest
{
public LureController Lure;
public Vector3 ThrowOriginPosition;
public Vector3 StartPosition;
public Vector3 Forward;
public float ChargedProgress;

View File

@@ -4,10 +4,13 @@ namespace NBF
{
public class ParabolaPlayerThrowAnimation : IPlayerThrowAnimation
{
public Player Player { get; set; }
private const int TrajectorySampleCount = 24;
private readonly float _minThrowDistance;
private readonly float _maxThrowDistance;
//
// private readonly float _minThrowDistance;
// private readonly float _maxThrowDistance;
private readonly float _throwDuration;
private readonly float _throwArcHeight;
private readonly float _targetHeightOffset;
@@ -24,15 +27,11 @@ namespace NBF
public bool IsPlaying => _castingLure != null;
public ParabolaPlayerThrowAnimation(
float minThrowDistance = 6f,
float maxThrowDistance = 25f,
float throwDuration = 0.65f,
float throwDuration = 0.45f,
float throwArcHeight = 4f,
float targetHeightOffset = 0f,
AnimationCurve throwHeightCurve = null)
{
_minThrowDistance = minThrowDistance;
_maxThrowDistance = maxThrowDistance;
_throwDuration = throwDuration;
_throwArcHeight = throwArcHeight;
_targetHeightOffset = targetHeightOffset;
@@ -55,15 +54,10 @@ namespace NBF
var lureBody = request.Lure.RBody;
_castStartPos = request.StartPosition;
Vector3 forward = request.Forward;
forward.y = 0f;
if (forward.sqrMagnitude < 0.001f)
{
forward = Vector3.forward;
}
Vector3 forward = GetHorizontalForward(request.Forward);
float distance = Mathf.Lerp(_minThrowDistance, _maxThrowDistance, _chargedProgress);
_castTargetPos = _castStartPos + forward.normalized * distance;
float distance = Mathf.Lerp(1, 8, _chargedProgress);
_castTargetPos = request.ThrowOriginPosition + forward * distance;
_castTargetPos.y = _castStartPos.y + _targetHeightOffset;
CacheTrajectoryPoints();
@@ -77,7 +71,6 @@ namespace NBF
public void Tick(float deltaTime)
{
DrawLastTrajectory();
UpdateCastAnimation(deltaTime);
}
@@ -131,6 +124,22 @@ namespace NBF
}
_hasLastTrajectory = true;
if (Player != null && Player.TrajectoryPoints != null)
{
Player.TrajectoryPoints.Clear();
Player.TrajectoryPoints.AddRange(_lastTrajectoryPoints);
}
}
private Vector3 GetHorizontalForward(Vector3 forward)
{
forward.y = 0f;
if (forward.sqrMagnitude < 0.001f)
{
return Vector3.forward;
}
return forward.normalized;
}
private Vector3 EvaluateTrajectoryPosition(float progress)
@@ -140,20 +149,5 @@ namespace NBF
position.y += arc;
return position;
}
private void DrawLastTrajectory()
{
if (!_hasLastTrajectory)
{
return;
}
for (int i = 1; i <= TrajectorySampleCount; i++)
{
Debug.DrawLine(_lastTrajectoryPoints[i - 1], _lastTrajectoryPoints[i], Color.yellow);
}
Debug.DrawRay(_lastTrajectoryPoints[TrajectorySampleCount], Vector3.up * 0.3f, Color.cyan);
}
}
}
}

View File

@@ -67,9 +67,11 @@ namespace NBF
}
_throwAnimation = CreateThrowAnimation(rod);
_throwAnimation.Player = Player;
_throwAnimation?.Play(new ThrowAnimationRequest
{
Lure = rod.Line.Lure,
ThrowOriginPosition = PlayerView.Unity.transform.position,
StartPosition = rod.Line.Lure.RBody.position,
Forward = PlayerView.Unity.transform.forward,
ChargedProgress = ChargedProgress

View File

@@ -60,8 +60,8 @@ namespace NBF
{
// await Task.Delay(100);
CommonTopPanel.Show();
SettingPanel.Show();
// LoginPanel.Show();
// SettingPanel.Show();
LoginPanel.Show();
// TestPanel.Show();