Use mouse to drag a node trough a Path2D

Godot Version

4.2

Question

Hello all,

I’m trying to create a puzzle interaction using a Node attached to a Path2D and a PathFollow2D, I expect to be able to drag that node over the path2D.

My attempts were using the global_position = get_global_mouse_position() but by changing the Node property in this way the PathFollow is ignored.

Any possible solution to it?

If you want the PathFollow2D node to do all the heavy lifting for you, then you can only influence it via its progres and/or progress_ratio properties. Increasing those values will move the node forward, decreasing them will move it backward.

Hi,
you can get the progress of PathFollow2D with ‘get_closest_offset’ method of the curve

path_follow_2d.progress = path_2d.curve.get_closest_offset( mouse_position )

Salud!

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.