0 votes

I am trying to use a Curve2D to draw a Bezier Curve exactly like the documentation:
https://docs.godotengine.org/en/3.2/tutorials/math/beziers_and_curves.html#adding-control-points

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: https://github.com/JohnMeadow1/GodotGeometryElements/tree/master/final/bezier_curve)

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 = Curve2D.new()

func _ready():
    # https://docs.godotengine.org/en/3.2/tutorials/math/beziers_and_curves.html
    var control0 = $P1.position-$P0.position
    var control1 = $P3.position-$P0.position
    curve.add_point($P0.position,control0,control1)

func _process(delta):
    $LineP0P1.points = Array()
    $LineP2P3.points = Array()
    $LineP0P1.add_point($P0.position)
    $LineP0P1.add_point($P1.position)
    $LineP2P3.add_point($P2.position)
    $LineP2P3.add_point($P3.position)

func _draw():
    # Draw the handles
    draw_circle($P0.position,5.0,Color(1.0,0,0,1.0))
    draw_circle($P1.position,5.0,Color(0,1.0,0,1.0))
    draw_circle($P2.position,5.0,Color(0,1.0,0,1.0))
    draw_circle($P3.position,5.0,Color(1.0,0,0,1.0))
    var curve_pts = curve.tessellate()
    print(curve_pts)

[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!

in Engine by (17 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.