How to get the closest point of a Path relative to an object?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By saladass
:warning: Old Version Published before Godot 3 was released.

I have a player, and I want the camera to be at the closest point of Path node Curve3D relative to the player origin. Could you give me a basic sample code, how can I implement this? Thanks in advance!

:bust_in_silhouette: Reply From: greygraphics

You can use Curve3D.get_closest_point() to get the closest point on the path.

is there an easy way to get the index of the closest point?

librepyxel | 2020-07-30 12:15

I was wondering this as well ^

StraightUpGruntled | 2021-01-11 09:11

The curve is baked from a set of points along a Bézier curve, so get_closest_point returns a point along that curve. This point does not need to be a control point. You can try to get the closest offset and search through the control points and compare their offsets. The closest offset should be the closest control point.

greygraphics | 2021-01-15 11:07