1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-06-02 09:21:54 +08:00

fix(BulletBase): 修复子弹分裂和折射时的空引用问题

确保在子弹分裂和折射时检查返回的子弹对象是否有效,避免空引用异常
This commit is contained in:
2026-03-22 08:16:35 +08:00
parent 7d6e396985
commit 3089af3ea0
4 changed files with 17 additions and 5 deletions
+5 -3
View File
@@ -12,13 +12,15 @@ func start():
running = true
func lifetime():
return Time.get_ticks_msec() - startTime
func periodPercent(count: int):
return lifetime() / period * deg_to_rad(360) - deg_to_rad(360.0 * count / len(bullets))
func getStateAngle(index: int):
return lifetime() / period * deg_to_rad(360) - deg_to_rad(360.0 * index / len(bullets))
func apply():
bullets = bullets.filter(is_instance_valid)
for index in len(bullets):
var bullet = bullets[index]
var offset = Vector2.from_angle(periodPercent(index))
var newStateAngle = lerp_angle(bullet.cycleStateAngle, getStateAngle(index), 0.1)
var offset = Vector2.from_angle(newStateAngle)
bullet.cycleStateAngle = newStateAngle
offset.y *= 0.25
bullet.position = bullet.launcher.position + offset * distance
bullet.scale = Vector2.ONE * (1 + offset.y)