Bullet rain is denser and its bullets are no longer stopped by anything

Interval dropped from 1.0s +- 0.6 to 0.4s +- 0.25 (about 2.5 bullets per second instead of 1), which measured 13 drops in 6 seconds versus 6 before. bullet.gd gained stop_on_obstacle (default false): the probe raycast is disabled, so rain bullets fall straight through terrain and ropes and are only recycled by their lifetime or by dropping past despawn_y. Verified a bullet falling from y=190 goes through the floor at y=225 and despawns at y=340. Also picks up the editor changes: the rope tiles were removed from level 3 and a few nodes gained unique ids.
This commit is contained in:
2026-10-07 23:01:00 +08:00
parent acc7901c2a
commit 8127c787f8
4 changed files with 20 additions and 20 deletions
+10 -3
View File
@@ -1,6 +1,6 @@
extends Area2D
## 弹幕子弹:直线飞行,碰到玩家扣血,撞到地形或超时消失。
## 弹幕子弹:直线飞行,碰到玩家扣血。
## 贴图是代码生成的实心圆,不需要额外美术素材。
@export var speed: float = 70.0
@@ -8,6 +8,11 @@ extends Area2D
@export var lifetime: float = 8.0
@export var radius: int = 3
@export var bullet_color: Color = Color(1.0, 0.35, 0.7)
## 撞到地形/绳子之类的障碍就消失。
## 关掉(默认)的话子弹会**穿过一切**,只靠存活时间和出界来回收
@export var stop_on_obstacle: bool = false
## 掉到这个世界 y 以下就自动回收(默认在关卡底部之外)
@export var despawn_y: float = 340.0
var direction: Vector2 = Vector2.LEFT
@@ -48,6 +53,8 @@ func _ready() -> void:
circle.radius = float(radius)
hit.shape = circle
_probe = get_node_or_null("Probe") as RayCast2D
if _probe != null:
_probe.enabled = stop_on_obstacle
body_entered.connect(_on_body_entered)
@@ -59,12 +66,12 @@ func launch(dir: Vector2, spd: float = -1.0) -> void:
func _physics_process(delta: float) -> void:
_age += delta
if _age >= lifetime:
if _age >= lifetime or global_position.y > despawn_y:
queue_free()
return
var step := direction * speed * delta
if _probe != null:
if stop_on_obstacle and _probe != null:
_probe.target_position = step * 1.5
_probe.force_raycast_update()
if _probe.is_colliding():
+7 -7
View File
@@ -1,20 +1,19 @@
extends Node2D
## 子弹雨:从天上随机横坐标往下落子弹,密度可以调得很疏。
## 子弹雨:从天上随机横坐标往下落子弹,密度可以调。
##
## 落下来的子弹撞到地形、或撞到你铺的「绳子/木板桥」就会消失 ——
## 绳子的碰撞放在 TileSet 的第 2 物理层,只有子弹的探针(mask = 3)会检测它,
## 玩家(mask = 1)和钥匙(跟着玩家的 mask)都不受影响,能直接穿过去。
## 落下来的子弹**不会被任何东西挡住**(bullet 的 stop_on_obstacle 默认关掉),
## 会一直穿到关卡底下才回收。
const BULLET := preload("res://scenes/prefabs/enemies/bullet.tscn")
@export var enabled: bool = true
## 平均多少秒落一颗(数值越大越稀疏)
@export var interval: float = 1.0
@export var interval: float = 0.4
## 间隔随机浮动范围(0 = 完全固定节奏)
@export var interval_jitter: float = 0.6
@export var interval_jitter: float = 0.25
## 开场后第一次落下的延迟
@export var start_delay: float = 1.5
@export var start_delay: float = 1.0
## 生成高度(相对自己的 y,负数 = 从屏幕上方外面)
@export var spawn_y: float = -30.0
## 水平撒落范围:以自己的 x 为中心,左右各一半
@@ -56,6 +55,7 @@ func drop() -> void:
bullet.bullet_color = bullet_color
bullet.speed = fall_speed
bullet.damage = damage
bullet.stop_on_obstacle = false
get_parent().add_child(bullet)
bullet.global_position = Vector2(
global_position.x + _rng.randf_range(-span * 0.5, span * 0.5),