- Edited
I'm in the process of adapting some code from the following page: https://github.com/thefryscorer/GodotPaintDemo/blob/master/world.gd (Special thanks to thefryscorer for sharing their code, and to TwistedTwigleg for showing me this repo!)
The following lines are where I discovered a peculiar behavior:
var alpha = factor_alpha/det
var beta = factor_beta/det
var gamma = 1.0 - alpha - beta
return Vector3(alpha, beta, gamma)
When the return Vector3(alpha, beta, gamma)
line is commented out, the code executes without issue. I can even print out factor_alpha
, factor_beta
, gamma
, and det
and see that they are all floats not equal to zero.
However, when I allow the return Vector3(alpha, beta, gamma)
line to execute, it causes the game to stop with a "Error: Division by zero in operator /" error, and points to the line where alpha
was set. (If I use constants instead of vars in the line for alpha
, beta
becomes the problem instead)
I tried static typing to make sure GDScript knows that the variables are floats, but this did not help.
What's going on? Does returning a Vector3 somehow change how GDScript interprets the previous variables?