Hello! I want to render links of chain on a given Path2d repeatedly and I actually achieved what I wanted with code:
var Chain = load("res://traps/saw/saw_chain.tscn")
const chain_size = 3
# Non relevant code is omitted. This method is called on ready
func _spawnChain():
var linksAmount = floor(path.curve.get_baked_length() / (chain_size * 2))
for i in linksAmount:
var link = Chain.instantiate()
path.add_child(link)
pathFollow.progress = chain_size + (chain_size * 2) * i
link.position = pathFollow.position
However I have a feeling that there should be a better way to do it. This is a very simple example because the path is static but what if the path is changing dynamically or what if it is acting like a spring? Another idea I have is to utilize Curve2D of the Path2D by either populating dots on it via script automatically and then rendering links on every such dot or, this part I’m not sure about because docs are kind of vague, by utilizing its bake_interval
somehow and getting all the cached points but I’m not sure how to do it. But even still I’m wondering if there is a way to achieve it without much coding or maybe even GPU based process via shaders?