36 lines
1.3 KiB
GDScript
36 lines
1.3 KiB
GDScript
extends Node
|
|
|
|
var minions = []
|
|
var minion_nav_point = []
|
|
var number_minions : int
|
|
var rot_amount : float
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
minions = self.get_children()
|
|
add_to_group("enemy_hivemind")
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta):
|
|
|
|
#calculate move position for each child
|
|
for i in minions:
|
|
if i.player != null:
|
|
#by number of minions determine the amount they should rotate around the player to be evenly distributed
|
|
number_minions = minions.size()
|
|
|
|
#return current array index
|
|
var minion_rot_amount = minions.find(i) * deg_to_rad(360 / number_minions)
|
|
var player_pos = i.player.global_transform.origin
|
|
var minion_pos = player_pos + Vector3(4,0,0)
|
|
var nav_pos : Vector3
|
|
|
|
nav_pos.x = player_pos.x + (minion_pos.x-player_pos.x)*cos(minion_rot_amount) - (minion_pos.z-player_pos.z)*sin(minion_rot_amount)
|
|
nav_pos.z = player_pos.z + (minion_pos.x-player_pos.x)*sin(minion_rot_amount) - (minion_pos.z-player_pos.z)*cos(minion_rot_amount)
|
|
|
|
i.nav_agent.set_target_position(nav_pos)
|
|
var next_nav_point = i.nav_agent.get_next_path_position()
|
|
|
|
i.hive_velocity = (next_nav_point - i.global_transform.origin).normalized() * i.SPEED
|