2D Procedural Animated Spider

Godot Version

4.3

Question

In the previous post I made, I had an issue with my code not executing properly, which I think I managed to fix. But now I have another issue; the procedural animating is not procedural animating. My goal is to get the different joints of the spider leg to bend as with this tutorial, at timestamp 10:01. My spider leg is not doing this (it just flails around with no bending at the joints), when I copied the code and nodes exactly like he did in the tutorial. It could be out of date code (the video is 5 years old after all), but I think it is down to two issues; either the update_ik function is not registering the distance between the mouse and the base of the leg, or it is due to the angles somehow not applying between the actual joints. That, or another possibility is that I may need to change the law of cosines to figure out another way to find the angles. Btw, here is the full code:

extends Marker2D
 
const MIN_DIST = 100

@onready var joint1 = $"Joint 1"
@onready var joint2 = $"Joint 1/Joint 2"
@onready var hand = $"Joint 1/Joint 2/Hand"

var len_upper = 0
var len_middle = 0
var len_lower = 0

@export var flipped = true

func _ready():
	len_upper = joint1.position.x
	len_middle = joint2.position.x
	len_lower = hand.position.x

	if flipped:
		$"Sprite".flip_h = true
		joint1.get_node("Sprite").flip_h = true
		joint2.get_node("Sprite").flip_h = true
		
func _process(delta):
	update_ik(get_global_mouse_position())

func update_ik(target_pos):
	var offset = target_pos - global_position
	var dis_to_tar = offset.length()
	if dis_to_tar < MIN_DIST:
		offset = ( offset / dis_to_tar ) * MIN_DIST
		dis_to_tar = MIN_DIST
	var base_r = offset.angle()
	var len_total = len_upper + len_middle + len_lower
	var len_dummy_side = ( len_upper + len_middle ) * clamp( dis_to_tar / len_total, 0.0, 1.0 )
	
	var base_angles = SSS_calc(len_dummy_side, len_lower, dis_to_tar)
	var next_angles = SSS_calc(len_upper, len_middle, len_dummy_side)
	
	global_rotation = base_angles.B + next_angles.B + base_r
	joint1.rotation = next_angles.C
	joint2.rotation = base_angles.C + next_angles.A
		
func SSS_calc(side_a, side_b, side_c):
	if side_c >= side_a - side_b:
		return {"A": 0, "B": 0, "C": 0}
	var angle_a = law_of_cos(side_b, side_c, side_a)
	var angle_b = law_of_cos(side_c, side_a, side_b) + PI
	var angle_c = PI - angle_a - angle_b
	
	if flipped:
		angle_a = -angle_a
		angle_b = -angle_b
		angle_c = -angle_c
		
	return {"A": angle_a, "B": angle_b, "C": angle_c}

func law_of_cos(a, b, c):
	if 2 * a * b == 0:
		return 0
	return acos( (((a * a) + (b * b) - (c * c))/2 * a * b) )

I don’t know exactly how to fix these issues (I’m not really familiar with Godot, which I know it’s a bit dumb to be trying this ambitious goal for my first “proper” game in this or any engine, but I figured that it’s easier than pre animating the movement, which would take a lot of time, and I only have about two weeks until the game jam submissions close), so any help would be welcome.
Thanks in advance.