Moving object toward targets

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Baloota

i’m new to godot and coding overall so bear with me

I have “Target” scene which include a script with var “active” of type bool

i have multiple levels scenes with different amount of “Target” instances

I have missile scene which i want to move toward any of the Target nodes.

now the question is, how do i get the missile to dynamically identify how many targets there are, where the target nodes are and know which one of them is active or not.

:bust_in_silhouette: Reply From: sirdorius

An easy way to do this would be to add your Target nodes to a “Target” group. Then in the missle script use get_tree().get_nodes_in_group("Target") to get a reference to all of them. Just be mindful that this is an expensive operation and you shouldn’t be doing it on every frame.

Thank you! It will be used only once when certain conditions are met.

Baloota | 2023-06-16 09:01