Good morning !
Bit new to godot and python, following many tutorials and testing things.
I was able to make my own version of a tutorial about tower defense.
Instead of having a pre-made path, i decided to use the towers to create the maze.
And so far so good ! Monsters adapt everytime i put a tower.
But. If a monster has spawn by the time i put a tower down, it will walk through it and ignore it. (Monsters spawn after i place the tower down will take the tower in consideration.
I think this is an easy fix.
Every-time I put down a tower, I need to refresh ALL enemy's path at once.
Problem is, i have no clue on how to update multiple "$entities.addchild(mobinstance)" at once.
I tried to google some solution, but i honestly don't even know what look for...
Any tutorial or idea on how i could take care of this ?
Here are 2 pieces of codes that matter :
When I place down a tower :
func build_tower():
#Need to add "If path_available" function to the IF
if can_build and not in_menu:
Map.set_cellv(current_tile, 16)
var new_tower = current_tower.instance()
new_tower.global_position = Map.map_to_world(current_tile)
$TowerContainer.add_child(new_tower)
#UPDDATE PATH OF ALL CHILD MONSTERS HERE
When I spawn a monster and create available path :
func _on_mob_spawn_timer_timeout():
var mob_instance = mob.instance()
#define STARTING psition and DESTINATIOnn
mob_instance.position = $start_position.position
mob_instance.destination = $end_position.position
#Define the path it will follow :
var path = $Nav.get_simple_path($start_position.position, $end_position.position)
mob_instance.set_path(path)
#add the mob to the entities container
if mobs_remaining > 0:
mobs_remaining -= 1
$mob_spawn_timer.start(.5)
$entities.add_child(mob_instance)
else:
mobs_remaining = 0
Thanks for your time