bugfix enemy spawner

This commit is contained in:
Michael Campbell 2026-03-04 02:27:43 -05:00
parent 5b659d7b9c
commit 2fd199612b
3 changed files with 7 additions and 6 deletions

View file

@ -30,11 +30,12 @@ func _process(_delta: float) -> void:
var col_mask := 16 # floor collision layer
var params := PhysicsRayQueryParameters3D.create(
v, v + Vector3.DOWN * 100., col_mask
v, v + Vector3.DOWN * 100., 1 # detect any level geometry
)
var raycast := get_world_3d().direct_space_state.intersect_ray(params)
if not raycast.is_empty():
# if the raycast hit and the hit was the floor...
if not raycast.is_empty() and raycast.collider.collision_layer & col_mask:
var hitpos: Vector3 = raycast.position
if points.size() < MAX_CACHED_POINTS:
@ -45,13 +46,15 @@ func _process(_delta: float) -> void:
doomed_point_idx = doomed_point_idx % MAX_CACHED_POINTS
func _on_timer_timeout() -> void:
if points.is_empty(): return
if points.is_empty():
push_warning("tried to spawn enemy, but can't find a point!")
return
var pos: Vector3 = points.pick_random()
pos += Vector3.UP * 0.02
var scene := preload("res://enemies/police_car/police_car.tscn")
var car: Node3D = scene.instantiate()
car.global_position = pos
car.position = pos
get_tree().current_scene.add_child(car)