godot-boids-experiments/scripts/Boid.gd

42 lines
966 B
GDScript

extends Node3D
class_name Boid
@export var max_timer : float = 10
@export var min_timer : float = 5
var velocity : Vector3 = Vector3(0, 0, 0)
var is_perching : bool = false
var perching_timer : Timer = Timer.new()
func _ready():
$Timer.wait_time = randf_range(min_timer, max_timer)
$Timer.start()
func _on_timer_timeout():
$Timer.wait_time = randf_range(min_timer, max_timer)
var dice : int = (randi() % 6) + 1
if dice == 6:
$SeagullSound2.play()
else:
$SeagullSound1.play()
func start_perching(min_perch_time : float, max_perch_time : float):
if is_perching:
return
if not perching_timer.timeout.is_connected(stop_perching):
add_child(perching_timer)
perching_timer.one_shot = true
perching_timer.timeout.connect(stop_perching)
is_perching = true
velocity = Vector3.UP
perching_timer.wait_time = randf_range(min_perch_time, max_perch_time)
perching_timer.start()
func stop_perching():
perching_timer.stop()
is_perching = false