|
|
@@ -9,8 +9,7 @@ public class Arrow : MonoBehaviour
|
|
|
public float flyTime = 0;
|
|
|
public bool isHit = false;
|
|
|
public RaycastHit absoluteRay;
|
|
|
- public RaycastHit finalRay;
|
|
|
- public Vector3 offsetAngle;
|
|
|
+ public float offsetAngle;
|
|
|
private float mySpeed = 0;
|
|
|
public bool simulatedParabola = false; //模拟抛物线
|
|
|
public ArmBow armBow;
|
|
|
@@ -37,17 +36,7 @@ public class Arrow : MonoBehaviour
|
|
|
redCircle.transform.position = -redCircle.transform.forward * 0.001f + absoluteRay.point;
|
|
|
}
|
|
|
if (absoluteRay.transform && absoluteRay.transform.gameObject.name == "TargetBody") {
|
|
|
- CalculateParabolaAngle(absoluteRay.point);
|
|
|
- bool hasAbsoluteAngleX = hasParabolaAngle;
|
|
|
- float absoluteAngleX = parabolaAngleInRadian / Mathf.PI * 180;
|
|
|
- bool hasFinalAngleX = false;
|
|
|
- float finalAngleX = 0;
|
|
|
- if (finalRay.transform && finalRay.transform.gameObject.name == "TargetBody") {
|
|
|
- CalculateParabolaAngle(finalRay.point);
|
|
|
- hasFinalAngleX = hasParabolaAngle;
|
|
|
- finalAngleX = parabolaAngleInRadian / Mathf.PI * 180;
|
|
|
- }
|
|
|
- SetUpBeforFly(hasAbsoluteAngleX, absoluteAngleX, hasFinalAngleX, finalAngleX);
|
|
|
+ SetUpBeforFly();
|
|
|
}
|
|
|
|
|
|
newRigidbody.velocity = this.transform.forward * mySpeed;
|
|
|
@@ -68,18 +57,31 @@ public class Arrow : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void SetUpBeforFly(bool hasAbsoluteAngleX, float absoluteAngleX, bool hasFinalAngleX, float finalAngleX)
|
|
|
+ void SetUpBeforFly()
|
|
|
{
|
|
|
+ CalculateParabolaAngle(absoluteRay.point);
|
|
|
+
|
|
|
float maxAngleX = 5;
|
|
|
- if (!hasAbsoluteAngleX) return;
|
|
|
+ if (!hasParabolaAngle) return;
|
|
|
+ float absoluteAngleX = parabolaAngleInRadian / Mathf.PI * 180;
|
|
|
if (absoluteAngleX > maxAngleX) return;
|
|
|
- if (hasFinalAngleX) {
|
|
|
+
|
|
|
+ float finalAngleX = absoluteAngleX + this.offsetAngle;
|
|
|
+ float vy = Mathf.Sin(finalAngleX / 180 * Mathf.PI) * this.mySpeed;
|
|
|
+ float vx = Mathf.Cos(finalAngleX / 180 * Mathf.PI) * this.mySpeed;
|
|
|
+ float deltaX = Mathf.Sqrt(Mathf.Pow(absoluteRay.point.x, 2) + Mathf.Pow(absoluteRay.point.z, 2));
|
|
|
+ float tx = deltaX / vx;
|
|
|
+ float dy = vy * tx + 0.5f * Physics.gravity.y * tx * tx;
|
|
|
+ Debug.Log(dy);
|
|
|
+ if (Mathf.Abs(dy) < 0.62f) {
|
|
|
+ finalPoint = absoluteRay.point;
|
|
|
+ finalPoint.y += dy;
|
|
|
useUpdatePhysics = true;
|
|
|
RandomUseSideCamera();
|
|
|
} else {
|
|
|
Vector3 eulerAngle = this.transform.eulerAngles;
|
|
|
- eulerAngle.x = -absoluteAngleX;
|
|
|
- this.transform.eulerAngles = eulerAngle + offsetAngle;
|
|
|
+ eulerAngle.x = -finalAngleX;
|
|
|
+ this.transform.eulerAngles = eulerAngle;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -148,10 +150,11 @@ public class Arrow : MonoBehaviour
|
|
|
|
|
|
bool useUpdatePhysics = false;
|
|
|
float flyTimeWithoutPhysics = 0;
|
|
|
+ Vector3 finalPoint = default;
|
|
|
void UpdateFlyWithoutPhysics() {
|
|
|
if (!useUpdatePhysics || isHit) return;
|
|
|
flyTimeWithoutPhysics += Time.deltaTime;
|
|
|
- Vector3 destination = finalRay.point;
|
|
|
+ Vector3 destination = finalPoint;
|
|
|
float deltaX = Mathf.Sqrt(
|
|
|
Mathf.Pow(destination.x - shootOutPosition.x, 2) +
|
|
|
Mathf.Pow(destination.z - shootOutPosition.z, 2)
|
|
|
@@ -180,7 +183,7 @@ public class Arrow : MonoBehaviour
|
|
|
}
|
|
|
|
|
|
public void Hit() {
|
|
|
- GameDebug.ins.ShowRes(absoluteRay.point, this.getHeadPosition(), offsetAngle);
|
|
|
+ GameDebug.ins.ShowRes(absoluteRay.point, this.getHeadPosition());
|
|
|
gameObject.GetComponent<BoxCollider>().enabled = false;
|
|
|
if (newRigidbody) {
|
|
|
newRigidbody.useGravity = false;
|