Multiple Children on FollowPath2D with different offsets

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

Can you have a single path with multiple nodes spawned in, through code, that start at different offsets on the path?

I want to spawn X number of monsters based on a signal timer.

   func _process(delta):	
    	pathToFollow.set_offset(pathToFollow.get_offset() + 350 * delta)

func _on_EnemySpawner_timeout():
	print("timeout!")
	var BubbleWingInstance = BubbleWing.instance()
	pathToFollow.add_child(BubbleWingInstance)

Can I spawn in a monster, on the first point of the path and have it follow the path?

:bust_in_silhouette: Reply From: kidscancode

It would be easier to use a PathFollow2D for each monster. Move their offsets independently.

Also, instead of

pathToFollow.set_offset(pathToFollow.get_offset() + 350 * delta)

you can just do

pathToFollow.offset += 350 * delta

I could do that - do you think the overhead of having 30 or 40 PathFollow2D on screen at one time is better than doing a tween between nodes and managing the paths manually?

GeneralAdein | 2020-06-17 13:07

It’s almost always better to use built-in methods than do it manually. If you’re already spawning 30-40 objects, what’s the harm in one more node for each of them?

kidscancode | 2020-06-17 14:32