I have a constraint-based chain composed of segments where each of the terminal segments has a fixed position.
My constraints are set up as follows:
var segments = [segment0, segment1, segment2, segment3, segment4, segment5, segment6] # terminal segments follow head and anchor segments.global_position = head.global_position segments[segments.size() - 1].global_position = anchor.global_position for x in range(4): # iterate 4 times for i in segments.size() - 1: var desired_distance = 8 var current_segment = segments[i] var prev_segment_position = current_segment.global_position if i == 0 or i == segments.size() - 1 else segments[i - 1].global_position var next_segment_position = current_segment.global_position if i == 0 or i == segments.size() - 1 else segments[i + 1].global_position # get vector from previous to next and find midpoint var prev_to_next = next_segment_position - prev_segment_position var midpoint = prev_segment_position + prev_to_next.normalized() * prev_to_next.length() * 1/2 # move current segment to midpoint var vec_to_midpoint = midpoint - current_segment.global_position current_segment.global_position += vec_to_midpoint
My question is: How can I implement random undulation in this chain?
In other words, I want the intermediate segments to move smoothly in a random wave pattern, while the terminal segments remain fixed to their positions.
Ideally, I'd set it up with some parameters than I could adjust to control the speed and volatility of the undulation.
I am working in Godot 3.1, but would like an engine-neutral explanation of the technique.