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

20 lines
759 B
GDScript3
Raw Normal View History

2024-08-19 16:53:54 +03:00
extends Node2D
func _ready() -> void:
2024-08-30 01:32:01 +03:00
for flock in get_children():
if flock is not Flock2D: continue
var color = Color(randf_range(0.8, 1.5), randf_range(0.8, 1.5), randf_range(0.2, 1.5), 1)
for i in 100: spawnBoid(flock, color)
2024-08-19 16:53:54 +03:00
func _process(delta: float) -> void:
2024-08-30 01:32:01 +03:00
$Path2D/PathFollow2D.progress_ratio += delta * 0.125
$Path2D2/PathFollow2D.progress_ratio += delta * 0.1
$Path2D3/PathFollow2D.progress_ratio += delta * 0.08
2024-08-19 16:53:54 +03:00
2024-08-30 01:32:01 +03:00
func spawnBoid(flock: Flock2D, color: Color) -> void:
var boid: Boid2D = preload("../example_boid.tscn").instantiate()
2024-08-19 16:53:54 +03:00
var screensize := get_viewport_rect().size
2024-08-30 01:32:01 +03:00
boid.modulate = color
2024-08-19 16:53:54 +03:00
boid.global_position = Vector2((randf_range(200, screensize.x - 200)), (randf_range(200, screensize.y - 200)))
2024-08-30 01:32:01 +03:00
flock.add_child(boid)