I commented out several lines and tried several things before realizing the it was the Vector3 line that was causing the issue. (I'm not sure if it actually is, all I know is that the error only happens if I allow it to run)
Putting a breakpoint on line 1 revealed the following values:
det = -0.117
factor_alpha = -0.009
factor_beta = 0.66
alpha = -0.009
So the error itself is still confusing. None of these values are 0. They are close to zero, however, so maybe it's a floating point precision issue?
I actually never thought to use a breakpoint, so thank you for that suggestion!
Edit: Here's the entire method:
func barycentric(P, A, B, C):
var det = matrix3x3_determinant(A, B, C)
var factor_alpha = matrix3x3_determinant(P, B, C)
var factor_beta = matrix3x3_determinant(P, C, A)
var alpha = factor_alpha / det
var beta = factor_beta / det
var gamma = 1.0 - alpha - beta
return Vector3(alpha, beta, gamma)
Using a breakpoint, I can see that somehow the Y value of P, A, B and C are all getting set to zero, which is what's causing the divide by zero error. That only happens when the Vector3 line is in? Again, I'm just so confused as to how constructing a new Vector3 is affecting old variables that were already set