I don't do 2D, but I've roughed up a quick example of what I described above, where I'm just setting the pre_a and pre_b handles to be 'arcHeight' above their respective Origin/Target vectors.:
@tool
extends ColorRect
@export var arcHeight := 50.0
@export var resolution := 10
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var curvepoints = PackedVector2Array()
for idx in range(0,resolution+1):
curvepoints.append($Origin.position.cubic_interpolate($Target.position, Vector2($Origin.position.x,$Origin.position.y+arcHeight), Vector2($Target.position.x,$Target.position.y+arcHeight), float(idx)/float(resolution)))
$Line2D.points = curvepoints
You could then alter the profile of the curve by offseting the pre_a/b vectors as desired, or programmatically alter arcHeight depending on other factors.
Again I don't do 2D, but I imagine you could also use this to sample points along this trajectory to identify collisions for example and stop the curve early. Someone feel free to chip on what the 'best' way to do this would be.
Edit: More fun stuff, by editing the positions of pre_a and pre_b relative to origin/target vectors you can get easy bendy splines (though would need to tweak to your liking:
and the code:
@tool
extends ColorRect
@export var resolution := 10
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var curvepoints = PackedVector2Array()
$pre_a.position = Vector2($Origin.position.x+($Target.position.x - $Origin.position.x)*0.3,$Target.position.y+($Target.position.y-$Origin.position.y)*2.0)
$pre_b.position = Vector2($Target.position.x+($Origin.position.x - $Target.position.x)*0.3,$Origin.position.y+($Origin.position.y-$Target.position.y)*2.0)
for idx in range(0,resolution+1):
curvepoints.append($Origin.position.cubic_interpolate($Target.position, $pre_a.position, $pre_b.position, float(idx)/float(resolution)))
$Line2D.points = curvepoints
When might you use something like this (at least in3D)?