2020-01-10 20:38:12 +01:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
export var member: PackedScene
|
|
|
|
|
|
|
|
|
2020-01-16 16:04:27 +01:00
|
|
|
func setup(
|
2020-01-22 17:55:49 +01:00
|
|
|
linear_speed_max: float,
|
|
|
|
linear_accel_max: float,
|
2020-01-16 16:04:27 +01:00
|
|
|
proximity_radius: float,
|
|
|
|
separation_decay_coefficient: float,
|
|
|
|
cohesion_strength: float,
|
|
|
|
separation_strength: float,
|
|
|
|
show_proximity_radius: bool
|
|
|
|
) -> void:
|
2020-01-16 09:44:44 +01:00
|
|
|
var followers := []
|
2020-01-10 20:38:12 +01:00
|
|
|
for i in range(19):
|
2020-01-16 09:44:44 +01:00
|
|
|
var follower := member.instance()
|
2020-01-10 20:38:12 +01:00
|
|
|
add_child(follower)
|
|
|
|
follower.position += Vector2(rand_range(-60, 60), rand_range(-60, 60))
|
|
|
|
followers.append(follower)
|
2020-01-15 20:15:31 +01:00
|
|
|
follower.setup(
|
2020-01-22 17:55:49 +01:00
|
|
|
linear_speed_max,
|
|
|
|
linear_accel_max,
|
2020-01-16 16:04:27 +01:00
|
|
|
proximity_radius,
|
|
|
|
separation_decay_coefficient,
|
|
|
|
cohesion_strength,
|
|
|
|
separation_strength
|
2020-01-15 20:15:31 +01:00
|
|
|
)
|
2020-01-16 16:04:27 +01:00
|
|
|
if i == 0 and show_proximity_radius:
|
2020-01-15 20:15:31 +01:00
|
|
|
follower.draw_proximity = true
|
|
|
|
follower.update()
|
2020-01-16 09:44:44 +01:00
|
|
|
var agents := []
|
2020-01-10 20:38:12 +01:00
|
|
|
for i in followers:
|
|
|
|
agents.append(i.agent)
|
|
|
|
for i in followers:
|
|
|
|
i.proximity.agents = agents
|
2020-01-15 20:15:31 +01:00
|
|
|
|
|
|
|
|
2020-01-22 17:55:49 +01:00
|
|
|
func set_linear_speed_max(value: float) -> void:
|
2020-01-15 20:15:31 +01:00
|
|
|
for child in get_children():
|
2020-01-22 17:55:49 +01:00
|
|
|
child.agent.linear_speed_max = value
|
2020-01-15 20:15:31 +01:00
|
|
|
|
|
|
|
|
2020-01-22 17:55:49 +01:00
|
|
|
func set_linear_accel_max(value: float) -> void:
|
2020-01-15 20:15:31 +01:00
|
|
|
for child in get_children():
|
2020-01-22 17:55:49 +01:00
|
|
|
child.agent.linear_acceleration_max = value
|
2020-01-15 20:15:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
func set_proximity_radius(value: float) -> void:
|
|
|
|
for child in get_children():
|
|
|
|
child.proximity.radius = value
|
|
|
|
if child == get_child(0):
|
|
|
|
child.update()
|
|
|
|
|
|
|
|
|
|
|
|
func set_show_proximity_radius(value: bool) -> void:
|
|
|
|
get_child(0).draw_proximity = value
|
|
|
|
get_child(0).update()
|
|
|
|
|
|
|
|
|
|
|
|
func set_separation_decay_coef(value: float) -> void:
|
|
|
|
for child in get_children():
|
|
|
|
child.separation.decay_coefficient = value
|
|
|
|
|
|
|
|
|
|
|
|
func set_cohesion_strength(value: float) -> void:
|
|
|
|
for child in get_children():
|
|
|
|
child.blend.get_behavior_at(1).weight = value
|
|
|
|
|
|
|
|
|
|
|
|
func set_separation_strength(value: float) -> void:
|
|
|
|
for child in get_children():
|
|
|
|
child.blend.get_behavior_at(0).weight = value
|