|
|
@@ -34,7 +34,8 @@ public class ArrowCamera : MonoBehaviour
|
|
|
}
|
|
|
else {
|
|
|
//射空就使用之前的镜头
|
|
|
- arrowCameraTemplate = new ArrowCameraTemplate1(this);
|
|
|
+ //arrowCameraTemplate = new ArrowCameraTemplate1(this);
|
|
|
+ arrowCameraTemplate = new ArrowCameraTemplate_targetLock(this, TargetBody.ins.transform,false);
|
|
|
}
|
|
|
|
|
|
//if ((isArrowSync && arrowSync.canUseSideCamera) || (!isArrowSync && arrow.canUseSideCamera)) {
|
|
|
@@ -292,6 +293,7 @@ class ArrowCameraTemplate_targetLock : ArrowCameraTemplate
|
|
|
|
|
|
private bool cameraStopped = false; // 标记相机是否已停止(到达目标附近后停止更新位置)
|
|
|
private Transform target; // 被锁定的目标(通常是靶心)
|
|
|
+ private bool isFollowTarget = true;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 相机相对箭的偏移量
|
|
|
@@ -305,25 +307,29 @@ class ArrowCameraTemplate_targetLock : ArrowCameraTemplate
|
|
|
|
|
|
private float totalDist = 0f; // 初始相机与目标之间的水平总距离(用于计算进度)
|
|
|
|
|
|
+
|
|
|
// 调节参数
|
|
|
private const float extraSpeedMax = 100f; // 相机在箭方向上的额外冲击速度最大值(越大越“冲”)
|
|
|
private const float minLerpSpeed = 2f; // 插值时的最小速度(进度小的时候)
|
|
|
private const float maxLerpSpeed = 10f; // 插值时的最大速度(进度接近 1 时)
|
|
|
|
|
|
- public ArrowCameraTemplate_targetLock(ArrowCamera arrowCamera, Transform target) : base(arrowCamera)
|
|
|
+ public ArrowCameraTemplate_targetLock(ArrowCamera arrowCamera, Transform target,bool followTarget = true) : base(arrowCamera)
|
|
|
{
|
|
|
//在 ArmBow.ins 调试参数
|
|
|
- offsetFromArrow = ArmBow.ins.offsetFromArrow;
|
|
|
+ offsetFromArrow = followTarget? ArmBow.ins.offsetFromArrow : ArmBow.ins.offsetFromArrowTemp;
|
|
|
stopDistanceToTarget = ArmBow.ins.stopDistanceToTarget;
|
|
|
|
|
|
this.target = target;
|
|
|
+ this.isFollowTarget = followTarget;
|
|
|
|
|
|
Transform cameraT = arrowCamera.transform;
|
|
|
Transform arrowT = arrowCamera.isArrowSync ? arrowCamera.arrowSync.transform : arrowCamera.arrow.transform;
|
|
|
|
|
|
+
|
|
|
// 相机初始位置(箭位置 + 偏移,锁定 Y 高度)
|
|
|
Vector3 offsetPos = arrowT.position + arrowT.TransformDirection(offsetFromArrow);
|
|
|
offsetPos.y = target.position.y + offsetFromArrow.y;
|
|
|
+ offsetPos.x = target.position.x;
|
|
|
cameraT.position = offsetPos;
|
|
|
|
|
|
// 记录初始总路程(XZ 平面,不考虑高度差)
|
|
|
@@ -357,30 +363,77 @@ class ArrowCameraTemplate_targetLock : ArrowCameraTemplate
|
|
|
1f - (distToTarget - stopDistanceToTarget) / (totalDist - stopDistanceToTarget)
|
|
|
);
|
|
|
|
|
|
+ //Vector3 arrowScreenPos = cameraT.GetComponent<Camera>().WorldToViewportPoint(arrowT.position);
|
|
|
+ //bool isFollow = true;
|
|
|
+ //// 如果箭接近屏幕边缘,就往后退
|
|
|
+ //if (arrowScreenPos.x < -0.13f || arrowScreenPos.x > 1f ||
|
|
|
+ // arrowScreenPos.y < -0.13f || arrowScreenPos.y > 1f)
|
|
|
+ //{
|
|
|
+ // //UnityEditor.EditorApplication.isPaused = true;
|
|
|
+ // // offsetFromArrow.z = ArmBow.ins.offsetFromArrow.z - 2;
|
|
|
+ // // 用 Lerp 平滑过渡
|
|
|
+ // //float targetZ = ArmBow.ins.offsetFromArrow.z - 4f;
|
|
|
+ // // offsetFromArrow.z = Mathf.Lerp(offsetFromArrow.z, targetZ, Time.deltaTime * 2f);
|
|
|
+
|
|
|
+ // Debug.Log("箭离开屏幕!" + offsetFromArrow);
|
|
|
+ // isFollow = false;
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // //offsetFromArrow.z = ArmBow.ins.offsetFromArrow.z;
|
|
|
+ // isFollow = true;
|
|
|
+ //}
|
|
|
+
|
|
|
// 用缓动曲线计算归一化进度(决定移动节奏)
|
|
|
float easedT = ArmBow.ins.customCurveCamera.Evaluate(progress);
|
|
|
|
|
|
// 箭位置 + 偏移(相机保持与箭的相对位置,并锁定到目标的高度)
|
|
|
Vector3 offsetPos = arrowT.position + arrowT.TransformDirection(offsetFromArrow);
|
|
|
- offsetPos.y = target.position.y + offsetFromArrow.y;
|
|
|
+ //offsetPos.y = target.position.y + offsetFromArrow.y;
|
|
|
+ offsetPos.x = target.position.x;
|
|
|
|
|
|
- // 箭的水平前进方向(忽略 y 分量)
|
|
|
- Vector3 arrowDirXZ = new Vector3(arrowT.forward.x, 0f, arrowT.forward.z).normalized;
|
|
|
+ if (this.isFollowTarget)
|
|
|
+ {
|
|
|
+ // 箭的水平前进方向(忽略x, y 分量)arrowT.forward.x
|
|
|
+ Vector3 arrowDirXZ = new Vector3(0f, 0f, arrowT.forward.z).normalized;
|
|
|
|
|
|
- // 相机额外的位移偏移量(随 easedT 增强,越靠近目标越快)
|
|
|
- Vector3 extraOffset = arrowDirXZ * Mathf.Lerp(0f, extraSpeedMax, easedT) * Time.deltaTime;
|
|
|
+ // 相机额外的位移偏移量(随 easedT 增强,越靠近目标越快)
|
|
|
+ Vector3 extraOffset = arrowDirXZ * Mathf.Lerp(0f, extraSpeedMax, easedT) * Time.deltaTime;
|
|
|
|
|
|
- // 最终目标位置 = 箭偏移位置 + 额外速度偏移
|
|
|
- Vector3 targetPos = offsetPos + extraOffset;
|
|
|
+ // 最终目标位置 = 箭偏移位置 + 额外速度偏移
|
|
|
+ Vector3 targetPos = offsetPos + extraOffset;
|
|
|
+
|
|
|
+ // 相机向目标位置平滑插值(随曲线加速)
|
|
|
+ float speedFactor = Mathf.Lerp(minLerpSpeed, maxLerpSpeed, easedT);
|
|
|
+ cameraT.position = Vector3.Lerp(cameraT.position, targetPos, Time.deltaTime * speedFactor);
|
|
|
+ }
|
|
|
+ else {
|
|
|
|
|
|
- // 相机向目标位置平滑插值(随曲线加速)
|
|
|
- float speedFactor = Mathf.Lerp(minLerpSpeed, maxLerpSpeed, easedT);
|
|
|
- cameraT.position = Vector3.Lerp(cameraT.position, targetPos, Time.deltaTime * speedFactor);
|
|
|
+ // 最终目标位置 = 箭偏移位置
|
|
|
+ //offsetPos.z = arrowT.position.z - 5;
|
|
|
|
|
|
-//#if UNITY_EDITOR
|
|
|
-// Debug.Log($"progress:{progress:F2}, easedT:{easedT:F2}, speed:{speedFactor:F2}, extra:{extraOffset}");
|
|
|
-//#endif
|
|
|
+ // 箭的水平前进方向(忽略 y 分量)arrowT.forward.x
|
|
|
+ //Vector3 arrowDirXZ = new Vector3(0f, 0f, arrowT.forward.z).normalized;
|
|
|
+
|
|
|
+ // 相机额外的位移偏移量(随 easedT 增强,越靠近目标越快)
|
|
|
+ // Vector3 extraOffset = arrowDirXZ * Mathf.Lerp(0f, extraSpeedMax, easedT) * Time.deltaTime;
|
|
|
+
|
|
|
+ // 最终目标位置 = 箭偏移位置 + 额外速度偏移
|
|
|
+ //Vector3 targetPos = offsetPos + extraOffset;
|
|
|
+ // 相机向目标位置平滑插值(随曲线加速)
|
|
|
+ //float speedFactor = Mathf.Lerp(minLerpSpeed, maxLerpSpeed, easedT);
|
|
|
+ cameraT.position = offsetPos;// Vector3.Lerp(cameraT.position, targetPos, Time.deltaTime * speedFactor);
|
|
|
+ }
|
|
|
+ // 最后强制 y = 靶子高度,不受lerp影响
|
|
|
+ Vector3 fixedPos = cameraT.position;
|
|
|
+ fixedPos.y = target.position.y + offsetFromArrow.y;
|
|
|
+ cameraT.position = fixedPos;
|
|
|
+
|
|
|
+ //#if UNITY_EDITOR
|
|
|
+ // Debug.Log($"progress:{progress:F2}, easedT:{easedT:F2}, speed:{speedFactor:F2}, extra:{extraOffset}");
|
|
|
+ //#endif
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// 命中处理(箭命中目标后,1.5 秒后销毁相机对象)
|
|
|
@@ -389,6 +442,8 @@ class ArrowCameraTemplate_targetLock : ArrowCameraTemplate
|
|
|
{
|
|
|
if (isDeleting) return;
|
|
|
isDeleting = true;
|
|
|
+
|
|
|
+ cameraStopped = true;
|
|
|
Sequence seq = DOTween.Sequence();
|
|
|
seq.AppendInterval(1.5f);
|
|
|
seq.AppendCallback(() =>
|