Path Follow 3D progress moves toward the position as close to the player

Godot Version

4.3

Question

Hey,

I’m working on a 3D project using the add-on “Phantom Camera” (which is not important for the question I’m asking).

I wanted to know if it was possible to make the Path Follow progress attribute head to the location where he would be the nearest to a certain node (in my case the player)

I’m trying to do that, so I can place a child node to the path follow node which the camera can look at.

Thanks (and sorry for my english, it’s not my mother tongue) !

If you are using a Path3D it is definitely possible!

var path = $Path3D
var player = $player
var cam = $camera

func _process(delta: float) -> void:

	var player_pos = player.global_transform.origin
	var cam_pos = cam.global_transform.origin
	var p = path.curve.get_closest_point(path.to_local(player_pos))

	#just set the position
	cam.global_transform.origin = path.global_transform.origin + p

	#or using delta for smooth movement :)
	cam.global_transform.origin += ((path.global_transform.origin + p) - cam_pos) * (delta*5)