Curve3d get_closest_point() does not work

Godot Version



I am using a Curve3d as part of a game’s navigation . ( follow path is for moving a snake )

problem is for curved Get_closest_point() blatently does not work . It gives Nan,nan,nan for all its numbers .

Here is the line of code print("closest point “, line.curve.get_closest_point($Path3D/PathFollow3D18/MeshInstance3D.get_global_position()), " number of point”, line.curve.get_point_count())

and here is the output . → closest point (nan, nan, nan) number of point52

Note all these points are created on the curve in code , Somebody please help Curve3d is not well documented

Try to use the code format </> button so that your question is easier to understand.

Curve3D.get_closest_point() takes a vector3 in local space. You seem to be passing a global one. You need to work out where your meshinstance is in the local space of the curve.


var mesh = $Path3D/PathFollow3D18/MeshInstance3D
var curve = $Your/Curve3D
var ls = curve.to_local(mesh.get_global_position)

Am afk, so it may be a bit random.

oh sorry yea I didn’t know how to post code till you told me . But thank you ill try that at noon today and see what happens .

I had to change your code a little but it still failed var mesh = $Path3D/PathFollow3D18/MeshInstance3D var curve_2 = $Path3D var ls = curve_2.to_local(mesh.get_global_position()) print("closest point ", curve_2.curve.get_closest_point(ls))

but it still failed giving closest point (nan, nan, nan)