My code for shooting a basketball doesn't work

Godot Version

4.6.3

Question

I am trying to make code so that the basketball with have a perfect arc into the hoop. However, every tutorial I watch about parabolic trajectory and stuff like that is for 2d. I tried turning them 3d, but it just flies all around the court before landing in the hoop. I can’t show a video, because my PC is being weird, so sorry about that.

I don’t even know how something like this happens. Any help on how to make my shi code work would be greatly appreciated. Below is the script for the basketball.

extends RigidBody3D

@export var speed = 1
@export var dev_distance = 120
@export var dev_angle = 60

var p0_shot: Vector3
var p1_shot: Vector3
var p2_shot: Vector3

var t = 0

func _process(delta: float):
	set_destination(GameVariables.basket_pos_1)

func set_destination(destination):
	p0_shot = global_position
	p2_shot = destination
	
	var tilted_unit_vector = (p2_shot - p0_shot).normalized().rotated(GameVariables.basket_pos_1, deg_to_rad(-dev_angle))
	p1_shot = p0_shot + dev_distance * tilted_unit_vector

func _physics_process(delta):
	if t < 1:
		t += speed * delta
	
	position = position.bezier_interpolate(p0_shot, p1_shot, p2_shot, t)

Not sure what the fix is, but this from Wikipedia says the following:

A Bézier curve is defined by a set of control points P0 through Pn, where n is called the order of the curve (n = 1 for linear, 2 for quadratic, 3 for cubic, etc.). The first and last control points are always the endpoints of the curve; however, the intermediate control points generally do not lie on the curve.

So you need to use something like a Cubic Bezier Curve (4 Control Points)

Read this section: