A common bug with using acos and asin is that input outside -1 to 1 range will result in Nan output. This can occur due to floating point error in the input.
The standard solution is to provide safe_acos function with clamped input. For Godot it may make more sense to make the standard functions safe.
(cherry picked from commit 50c5ed4876)
Returns the arc cosine of [param x] in radians. Use to get the angle of cosine [param x]. [param x] must be between [code]-1.0[/code] and [code]1.0[/code] (inclusive), otherwise, [method acos] will return [constant @GDScript.NAN].
Returns the arc cosine of [param x] in radians. Use to get the angle of cosine [param x]. [param x] will be clamped between [code]-1.0[/code] and [code]1.0[/code] (inclusive), in order to prevent [method acos] from returning [constant @GDScript.NAN].
[codeblock]
[codeblock]
# c is 0.523599 or 30 degrees if converted with rad_to_deg(c)
# c is 0.523599 or 30 degrees if converted with rad_to_deg(c)
var c = acos(0.866025)
var c = acos(0.866025)
@ -76,7 +76,7 @@
<returntype="float"/>
<returntype="float"/>
<paramindex="0"name="x"type="float"/>
<paramindex="0"name="x"type="float"/>
<description>
<description>
Returns the arc sine of [param x] in radians. Use to get the angle of sine [param x]. [param x] must be between [code]-1.0[/code] and [code]1.0[/code] (inclusive), otherwise, [method asin] will return [constant @GDScript.NAN].
Returns the arc sine of [param x] in radians. Use to get the angle of sine [param x]. [param x] will be clamped between [code]-1.0[/code] and [code]1.0[/code] (inclusive), in order to prevent [method asin] from returning [constant @GDScript.NAN].
[codeblock]
[codeblock]
# s is 0.523599 or 30 degrees if converted with rad_to_deg(s)
# s is 0.523599 or 30 degrees if converted with rad_to_deg(s)