鱼竿弯曲

This commit is contained in:
2026-04-01 23:38:21 +08:00
parent 78bc4dfc53
commit 63bc9b5536
63 changed files with 489 additions and 1134 deletions

View File

@@ -10,6 +10,8 @@ namespace NBF
// [SerializeField] private Buoyancy _buoyancy;
public Rigidbody rbody => _rbody;
public Rigidbody JointRb => joint.connectedBody;
public void SetJoint(Rigidbody rb)
{
joint = joint == null ? GetComponent<ConfigurableJoint>() : joint;

View File

@@ -88,10 +88,10 @@ namespace NBF
_tension = value;
}
Scene.EventComponent.Publish(new PlayerItemRodLingChangeEvent
{
Item = this
});
// Scene.EventComponent.Publish(new PlayerItemRodLingChangeEvent
// {
// Item = this
// });
}
}

View File

@@ -22,15 +22,24 @@ namespace NBF
[SerializeField] private bool isLureConnect;
[SerializeField] private RodLine rodLine;
/// <summary>
/// 主线
/// </summary>
[SerializeField] private Rope fishingRope;
/// <summary>
/// 浮漂和鱼钩线
/// </summary>
[SerializeField] private Rope bobberRope;
public LureController Lure;
public BobberController Bobber;
public JointPinchController PinchController;
// public event Action OnLinePulled;
public float LinelenghtDiferent;
protected override void OnInit()
{
@@ -112,8 +121,6 @@ namespace NBF
Lure.RBody.useGravity = true;
}
public void SetTargetLength(float value)
{
Log.Error($"SetObiRopeStretch={value}");
@@ -121,13 +128,44 @@ namespace NBF
{
// value -= 0.2f;
}
fishingRope.SetTargetLength(value);
}
public void SetLureLength(float value)
{
Log.Error($"SetObiRopeStretch={value}");
bobberRope.SetTargetLength(value);
}
private void Update()
{
LinelenghtDiferent = GetLineDistance();
//非钓鱼状态
Rod.PlayerItem.Tension = Mathf.Clamp(LinelenghtDiferent, 0f, 0.05f);
}
#region Tension
private float GetLineDistance()
{
if (!Bobber.JointRb)
{
return 0;
}
//第一个节点到竿稍的位置-第一段鱼线长度
return Vector3.Distance(Bobber.transform.position, Bobber.JointRb.transform.position) -
fishingRope.GetCurrentLength();
}
public float GetTension(float weight)
{
return weight * GetLineDistance();
}
#endregion
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Fantasy;
using Fantasy.Async;
using NBC.Asset;
@@ -40,8 +41,14 @@ namespace NBF
Asset = GetComponent<RodAsset>();
}
private void Start()
{
Asset.CCDIK.enabled = true;
}
private void Update()
{
BendControl();
// if (Input.GetKeyDown(KeyCode.Alpha0))
// {
// SetLineLength(lineLength);
@@ -68,7 +75,8 @@ namespace NBF
Line.Lure.SetJointDistance(PlayerItem.LineLength);
if (PlayerItem.StretchRope)
{
Line.SetTargetLength(PlayerItem.Tension > 0f ? 0f : PlayerItem.LineLength);
// Line.SetTargetLength(PlayerItem.Tension > 0f ? 0f : PlayerItem.LineLength);
Line.SetTargetLength(PlayerItem.LineLength);
}
}
else
@@ -78,7 +86,8 @@ namespace NBF
Line.Bobber.SetJointDistance(PlayerItem.LineLength - PlayerItem.FloatLength);
if (PlayerItem.StretchRope)
{
Line.SetTargetLength(PlayerItem.Tension > 0f ? 0f : PlayerItem.LineLength - PlayerItem.FloatLength);
// Line.SetTargetLength(PlayerItem.Tension > 0f ? 0f : PlayerItem.LineLength - PlayerItem.FloatLength);
Line.SetTargetLength(PlayerItem.LineLength - PlayerItem.FloatLength);
Line.SetLureLength(PlayerItem.FloatLength);
}
}
@@ -115,8 +124,6 @@ namespace NBF
var obj = new GameObject($"rod_{ConfigId}");
obj.transform.SetParent(SceneSettings.Instance.GearNode);
// obj.transform.SetParent(player.transform);
// obj.transform.localPosition = Vector3.zero;
obj.transform.position = playerViewUnity.transform.position;
obj.transform.rotation = playerViewUnity.transform.rotation;
obj.transform.localScale = Vector3.one;
@@ -124,8 +131,6 @@ namespace NBF
var parent = GearRoot;
// List<ItemInfo> children = RoleModel.Instance.GetBindItems(itemInfo.Id);
CreateFishingHandler();
await FTask.WaitFrame(playerView.Scene); //等待1帧
// children.Sort();
@@ -301,6 +306,46 @@ namespace NBF
rings = list.ToArray();
}
#region 竿
private List<float> previousWeights = Enumerable.Repeat(0f, 10).ToList();
private float bendSmooth = 1f;
private void BendControl()
{
// Vector3 vector = (FishEntity.CurrentFishInFight
// ? FishEntity.CurrentFishInFight.transform.position
// : fishingLine.currentLineHandler.LineConnector_1.transform.position);
var ccdik = Asset.CCDIK;
Vector3 vector = Line.Bobber.transform.position;
// float num = Vector3.Distance(ccdik.solver.bones.Last().transform.position, vector);
float num2 = 0.05f;
float num6 = 0.3f;
// if (isThrowing)
// {
// num6 = 0.1f;
// }
// else if (!FishEntity.CurrentFishInFight)
// {
// num6 = 0.2f;
// }
float target = num2 * num6;
float item = Mathf.MoveTowards(ccdik.solver.IKPositionWeight, target, Time.deltaTime * bendSmooth);
previousWeights.RemoveAt(0);
previousWeights.Add(item);
float num7 = previousWeights.Average();
ccdik.solver.SetIKPosition(vector);
ccdik.solver.SetIKPositionWeight(num7);
}
#endregion
private void Test()
{
// var root = Player.ModelAsset.RodRoot;

View File

@@ -561,7 +561,7 @@ public class Rope : MonoBehaviour
LockAnchorsHard();
}
private void LateUpdate()
private void Update()
{
if (!startAnchor || !endAnchor || _pCurr == null || _physicsNodes < 2) return;