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)