godot_boids/examples/boids/2d/follow/example.gd

15 lines
481 B
GDScript3
Raw Normal View History

2024-08-19 16:53:54 +03:00
extends Node2D
func _ready() -> void:
for i in 40: spawnBoid()
func _process(delta: float) -> void:
$Path2D/PathFollow2D.progress_ratio += delta * 0.1
func spawnBoid() -> void:
var boid: Boid2D = preload("../example_boid.tscn").instantiate()
2024-08-19 16:53:54 +03:00
var screensize := get_viewport_rect().size
boid.modulate = Color(randf(), randf(), randf(), 1)
boid.global_position = Vector2((randf_range(200, screensize.x - 200)), (randf_range(200, screensize.y - 200)))
$Flock.add_child(boid)