修改提交

This commit is contained in:
2026-04-12 22:42:06 +08:00
parent c96255aaa5
commit de0b0558d6
2 changed files with 58 additions and 41 deletions

View File

@@ -188,6 +188,7 @@ namespace NBF
private bool _waterStateInitialized;
private float _defaultAngularDamping;
private bool _defaultUseGravity;
private RigidbodyConstraints _defaultConstraints;
private float _draftVelocity;
private float _currentDraftDepth;
@@ -195,6 +196,8 @@ namespace NBF
private float _biteOffsetY;
private float _biteOffsetYVelocity;
private bool _uprightPoseCached;
private Quaternion _cachedUprightRotation;
private Quaternion _uprightReferenceRotation;
private Quaternion _targetRotation;
@@ -284,8 +287,9 @@ namespace NBF
UpdateBiteAnimation(deltaTime);
UpdateDraft(deltaTime);
UpdateVerticalPosition(deltaTime);
UpdateRotation(deltaTime);
var nextRotation = CalculateNextRotation(deltaTime);
UpdateVerticalPosition(deltaTime, nextRotation);
ApplyRotation(nextRotation);
}
#endregion
@@ -360,6 +364,7 @@ namespace NBF
{
_defaultAngularDamping = _rb.angularDamping;
_defaultUseGravity = _rb.useGravity;
_defaultConstraints = _rb.constraints;
_defaultsCached = true;
}
@@ -368,12 +373,15 @@ namespace NBF
_ySmoothVelocity = 0f;
_biteOffsetY = 0f;
_biteOffsetYVelocity = 0f;
_targetRotation = transform.rotation;
_targetRotation = _rb.rotation;
if (!_waterStateInitialized)
if (!_uprightPoseCached)
{
_uprightReferenceRotation = transform.rotation;
_cachedUprightRotation = _rb.rotation;
_uprightPoseCached = true;
}
_uprightReferenceRotation = _cachedUprightRotation;
}
private void EnterWaterPresentationMode()
@@ -385,8 +393,8 @@ namespace NBF
_mode = FishingBobberControlMode.WaterPresentation;
_waterStateInitialized = true;
_uprightReferenceRotation = transform.rotation;
_targetRotation = transform.rotation;
_uprightReferenceRotation = _cachedUprightRotation;
_targetRotation = _rb.rotation;
_draftVelocity = 0f;
_ySmoothVelocity = 0f;
_biteOffsetYVelocity = 0f;
@@ -394,6 +402,8 @@ namespace NBF
_rb.useGravity = false;
_rb.angularDamping = waterAngularDamping;
_rb.constraints = _defaultConstraints | RigidbodyConstraints.FreezeRotation;
_rb.angularVelocity = Vector3.zero;
}
private void ExitWaterPresentationMode()
@@ -411,6 +421,7 @@ namespace NBF
_rb.useGravity = _defaultUseGravity;
_rb.angularDamping = _defaultAngularDamping;
_rb.constraints = _defaultConstraints;
}
private float GetSubmergeDepth()
@@ -442,10 +453,10 @@ namespace NBF
deltaTime);
}
private void UpdateVerticalPosition(float deltaTime)
private void UpdateVerticalPosition(float deltaTime, Quaternion targetRotation)
{
var position = transform.position;
var targetY = waterLevel - _currentDraftDepth - bottomOffsetLocalY + _biteOffsetY;
var position = _rb.position;
var targetY = waterLevel - _currentDraftDepth - GetBottomOffsetWorldY(targetRotation) + _biteOffsetY;
if (Mathf.Abs(position.y - targetY) < yDeadZone)
{
@@ -463,7 +474,7 @@ namespace NBF
deltaTime);
}
transform.position = position;
_rb.MovePosition(position);
var velocity = _rb.linearVelocity;
if (Mathf.Abs(velocity.y) > 0f)
@@ -473,7 +484,7 @@ namespace NBF
}
}
private void UpdateRotation(float deltaTime)
private Quaternion CalculateNextRotation(float deltaTime)
{
var targetTiltAngle = EvaluateTargetTiltAngle();
var signedAngle = invertTiltDirection ? -targetTiltAngle : targetTiltAngle;
@@ -481,12 +492,22 @@ namespace NBF
_targetRotation = _uprightReferenceRotation * Quaternion.AngleAxis(signedAngle, localAxis);
_rb.angularVelocity = Vector3.zero;
transform.rotation = Quaternion.Slerp(
transform.rotation,
return Quaternion.Slerp(
_rb.rotation,
_targetRotation,
1f - Mathf.Exp(-Mathf.Max(0.01f, rotationLerpSpeed) * deltaTime));
}
private void ApplyRotation(Quaternion nextRotation)
{
_rb.rotation = nextRotation;
}
private float GetBottomOffsetWorldY(Quaternion rotation)
{
return (rotation * new Vector3(0f, bottomOffsetLocalY, 0f)).y;
}
private float EvaluateTargetTiltAngle()
{
if (currentBottomWeight <= lyingWeightThreshold)