根据提供的code differences信息,由于没有具体的代码变更内容,我将生成一个通用的commit message模板:

```
docs(readme): 更新文档说明

- 添加项目使用指南
- 完善API接口说明
- 修正错误的配置示例
```

注意:由于您提供的code differences部分为空,以上是一个示例模板。当您有具体的代码变更时,请提供详细的变更内容以便生成更准确的commit message。
This commit is contained in:
huadexuan committed 2026-10-14 00:11:54 +08:00
1 parent 8cbe8e000b
commit 1a84ea999e
36 files changed
+32672 -136

No files matched your search

+59 -14
View File
@@ -5,6 +5,10 @@ public class Projectile : MonoBehaviour
[Header("爆炸效果(可选)")]
public GameObject explosionPrefab; // 爆炸特效预制体,留空则没有爆炸效果
[Header("抛物线飞行(可选)")]
public bool useParabola = false; // 是否启用小抛物线飞行
public float parabolaHeight = 1.0f; // 抛物线最高拱起高度 (不太高的抛物线)
private GameObject target;
private GameObject owner;
private float damage;
@@ -13,6 +17,9 @@ public class Projectile : MonoBehaviour
private bool registerEnergyOnHit;
private bool initialized;
private bool hasHit;
private Vector3 startPosition;
private float totalFlyDistance;
private float horizontalTraveled;
public void Initialize(
GameObject targetObject,
@@ -31,6 +38,19 @@ public class Projectile : MonoBehaviour
initialized = true;
hasHit = false;
startPosition = transform.position;
horizontalTraveled = 0f;
if (targetObject != null)
{
Vector3 diff = targetObject.transform.position - startPosition;
diff.y = 0f;
totalFlyDistance = Mathf.Max(0.1f, diff.magnitude);
}
else
{
totalFlyDistance = 10f;
}
// The projectile uses its own raycast hit check. Disable the collider so
// it cannot be destroyed or disturbed by the owner's launch socket.
foreach (var collider in GetComponentsInChildren<Collider>(true))
@@ -57,27 +77,56 @@ public class Projectile : MonoBehaviour
return;
}
// 目标根节点位于脚底,只取水平差值,让箭保持当前高度平行飞行。
Vector3 offset = target.transform.position - transform.position;
offset.y = 0f;
if (offset.sqrMagnitude <= 0.01f)
Vector3 targetCurrentPos = target.transform.position;
Vector3 offset = targetCurrentPos - transform.position;
Vector3 flatOffset = new Vector3(offset.x, 0f, offset.z);
if (flatOffset.sqrMagnitude <= 0.04f)
{
HitTarget(target);
return;
}
Vector3 direction = offset.normalized;
float distance = speed * Time.deltaTime;
if (distance >= offset.magnitude)
Vector3 direction = flatOffset.normalized;
float step = speed * Time.deltaTime;
horizontalTraveled += step;
if (step >= flatOffset.magnitude)
{
HitTarget(target);
return;
}
// 投射物保持水平飞行,并让根节点前方始终指向当前目标。
transform.rotation = Quaternion.LookRotation(direction, Vector3.up);
Vector3 nextPos;
if (useParabola && totalFlyDistance > 0.1f)
{
// 水平线性推进
float t = Mathf.Clamp01(horizontalTraveled / totalFlyDistance);
Vector3 groundPos = Vector3.Lerp(new Vector3(startPosition.x, 0.1f, startPosition.z), new Vector3(targetCurrentPos.x, 0.1f, targetCurrentPos.z), t);
// 抛物线高度:基础发射高度渐变 + 4 * h * t * (1 - t) 抛物线弧度
float startY = startPosition.y;
float targetY = targetCurrentPos.y + 0.8f;
float baseY = Mathf.Lerp(startY, targetY, t);
float arcY = 4f * parabolaHeight * t * (1f - t);
nextPos = new Vector3(groundPos.x, baseY + arcY, groundPos.z);
if (Physics.Raycast(transform.position, direction, out RaycastHit hit, distance))
// 矛身旋转:朝向移动切线方向,矛头顺着抛物线弧度自然俯仰
Vector3 velocity = (nextPos - transform.position);
if (velocity.sqrMagnitude > 1e-6f)
{
transform.rotation = Quaternion.LookRotation(velocity.normalized, Vector3.up);
}
transform.position = nextPos;
}
else
{
// 水平直线飞行
transform.rotation = Quaternion.LookRotation(direction, Vector3.up);
transform.position += direction * step;
}
if (Physics.Raycast(transform.position, direction, out RaycastHit hit, step))
{
TryHit(hit.collider.gameObject);
if (hit.collider.transform.root == target.transform.root)
@@ -85,10 +134,6 @@ public class Projectile : MonoBehaviour
return;
}
}
// 火球保持 Prefab 固定角度,不随飞行方向旋转
// transform.forward = direction;
transform.position += direction * distance;
}
private void OnTriggerEnter(Collider other)