Using Curve2D to draw a Bezier Curve

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

I am trying to use a Curve2D to draw a Bezier Curve exactly like the documentation:

I found an example of manually calculating all of the points in a Bezier curve, but I’d like to use Curve2D properly so I can take advantage of the Tessellate function which as I understand it will give me a reduced number of points for areas of minimal curvature (the manual example is here:

I am having trouble with adding points to the Curve2D - I believe the mistake is in the “in” and “out” arguments. Can someone help me figure out how I can just get nice control nodes and define a Bezier curve properly so I can tessellate (so I use the Godot functionality of Curve2D properly!)

I have a (very simple) project with 4 Position2D nodes added to it, and the following script:

Cubic Bezier Project (Simple)

extends Node2D

onready var curve =

func _ready():
	var control0 = $P1.position-$P0.position
	var control1 = $P3.position-$P0.position

func _process(delta):
	$LineP0P1.points = Array()
	$LineP2P3.points = Array()
func _draw():
	# Draw the handles
	var curve_pts = curve.tessellate()

[Edit] Where I’m going with this is having movable control and end points, which can interact with another node when it is hovering over them, and that light up when the mouse is near the bezier curve (so the user knows it is selectable). Any shove in the right direction is greatly appreciated. Thanks everyone!

:bust_in_silhouette: Reply From: pouing

You can define the Bezier curve by adding the two points P0 and P3, with “outer” param as (0,0) and “inner” param to be the control points:

 func _ready():
    var control0 = $P1.position-$P0.position
    var control1 = $P2.position-$P3.position
    curve.add_point($P0.position, Vector2.ZERO, control0)
    curve.add_point($P3.position, control1, Vector2.ZERO)

Also note the sign change for control1.