|
|
@@ -307,6 +307,9 @@ class ArrowCameraTemplate_targetLock : ArrowCameraTemplate
|
|
|
|
|
|
private float totalDist = 0f; // 初始相机与目标之间的水平总距离(用于计算进度)
|
|
|
|
|
|
+ private Vector3 lastArrowPos; // 记录箭的上一次位置
|
|
|
+
|
|
|
+ private float arrowSpeed = 0;
|
|
|
|
|
|
// 调节参数
|
|
|
private const float extraSpeedMax = 100f; // 相机在箭方向上的额外冲击速度最大值(越大越“冲”)
|
|
|
@@ -320,11 +323,12 @@ class ArrowCameraTemplate_targetLock : ArrowCameraTemplate
|
|
|
stopDistanceToTarget = ArmBow.ins.stopDistanceToTarget;
|
|
|
|
|
|
this.target = target;
|
|
|
+
|
|
|
this.isFollowTarget = followTarget;
|
|
|
|
|
|
Transform cameraT = arrowCamera.transform;
|
|
|
Transform arrowT = arrowCamera.isArrowSync ? arrowCamera.arrowSync.transform : arrowCamera.arrow.transform;
|
|
|
-
|
|
|
+ this.lastArrowPos = arrowT.position;
|
|
|
|
|
|
// 相机初始位置(箭位置 + 偏移,锁定 Y 高度)
|
|
|
Vector3 offsetPos = arrowT.position + arrowT.TransformDirection(offsetFromArrow);
|
|
|
@@ -334,6 +338,9 @@ class ArrowCameraTemplate_targetLock : ArrowCameraTemplate
|
|
|
|
|
|
// 记录初始总路程(XZ 平面,不考虑高度差)
|
|
|
totalDist = GetXZDistance(offsetPos, target.position);
|
|
|
+
|
|
|
+ arrowSpeed = arrowCamera.arrow.mySpeed;
|
|
|
+ Debug.Log("当前弓箭速度:" + arrowSpeed);
|
|
|
}
|
|
|
|
|
|
public override void Update()
|
|
|
@@ -390,7 +397,7 @@ class ArrowCameraTemplate_targetLock : ArrowCameraTemplate
|
|
|
// 箭位置 + 偏移(相机保持与箭的相对位置,并锁定到目标的高度)
|
|
|
Vector3 offsetPos = arrowT.position + arrowT.TransformDirection(offsetFromArrow);
|
|
|
//offsetPos.y = target.position.y + offsetFromArrow.y;
|
|
|
- offsetPos.x = target.position.x;
|
|
|
+ // offsetPos.x = target.position.x;
|
|
|
|
|
|
if (this.isFollowTarget)
|
|
|
{
|
|
|
@@ -408,10 +415,8 @@ class ArrowCameraTemplate_targetLock : ArrowCameraTemplate
|
|
|
cameraT.position = Vector3.Lerp(cameraT.position, targetPos, Time.deltaTime * speedFactor);
|
|
|
}
|
|
|
else {
|
|
|
-
|
|
|
// 最终目标位置 = 箭偏移位置
|
|
|
//offsetPos.z = arrowT.position.z - 5;
|
|
|
-
|
|
|
// 箭的水平前进方向(忽略 y 分量)arrowT.forward.x
|
|
|
//Vector3 arrowDirXZ = new Vector3(0f, 0f, arrowT.forward.z).normalized;
|
|
|
|
|
|
@@ -422,7 +427,30 @@ class ArrowCameraTemplate_targetLock : ArrowCameraTemplate
|
|
|
//Vector3 targetPos = offsetPos + extraOffset;
|
|
|
// 相机向目标位置平滑插值(随曲线加速)
|
|
|
//float speedFactor = Mathf.Lerp(minLerpSpeed, maxLerpSpeed, easedT);
|
|
|
- cameraT.position = offsetPos;// Vector3.Lerp(cameraT.position, targetPos, Time.deltaTime * speedFactor);
|
|
|
+ //cameraT.position = offsetPos;// Vector3.Lerp(cameraT.position, targetPos, Time.deltaTime * speedFactor);
|
|
|
+ cameraT.SetParent(null);
|
|
|
+
|
|
|
+ // 箭的前进方向(XZ 平面)Z 分量
|
|
|
+ float arrowSpeedZ = arrowSpeed * arrowT.forward.z; // 箭速度 * 前方向 Z 分量
|
|
|
+
|
|
|
+ // 相机当前 Z 位置参考箭的 Z
|
|
|
+ float targetZ = cameraT.position.z + arrowSpeedZ * Time.deltaTime;
|
|
|
+
|
|
|
+ // 保证相机不要超过箭本身(可选)
|
|
|
+ targetZ = Mathf.Min(targetZ, arrowT.position.z);
|
|
|
+
|
|
|
+ // 目标位置 = 相机 X/Y 偏移不变,Z 方向用 targetZ
|
|
|
+ Vector3 targetPos = new Vector3(
|
|
|
+ target.position.x, // X 可以锁定到目标或保持 offsetPos.x
|
|
|
+ offsetPos.y, // Y 维持箭高度偏移
|
|
|
+ targetZ
|
|
|
+ );
|
|
|
+
|
|
|
+ // 直接插值平滑到目标位置(也可以加缓动)
|
|
|
+ float speedFactor = 5f; // 可调节平滑程度
|
|
|
+ cameraT.position = Vector3.Lerp(cameraT.position, targetPos, Time.deltaTime * speedFactor);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
// 最后强制 y = 靶子高度,不受lerp影响
|
|
|
Vector3 fixedPos = cameraT.position;
|