#How do I instantiate an enemy along a path 2D?

6 messages · Page 1 of 1 (latest)

kindred hemlock
#

if you want to instantiate a node along a path, you would probably put a pathfollow2d node as a child of the path and set its progress ratio to a float between 0 and 1, representing 0 and 100% of the path's length. Then use its position as the position for the new node

violet hearth
#

I tried to do that, but the code isnt working, do u think u could take a look? func _ready() -> void:
create_enemies_on_path($Path2D/PathFollow2D.progress_ratio.randf_range(0, 1))

func create_enemies_on_path(pos):
var create_enemy = enemy_preload.instantiate()
create_enemy.position = pos
add_child(create_enemy)

#

this is my error

#

E 0:00:01:0324 game.gd:6 @ _ready(): Node not found: "Path2D/PathFollow2D" (relative to "/root/Game").
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1792 @ get_node()
<Stack Trace> game.gd:6 @ _ready()

#

Oh, i'm just stupid

sweet onyx