I have not used Path2D myself, but it looks like unless you want to use Path2DFollower, then you'll need to interface with the Curve2D stored in the Path2D.
Then I think you'll just need to use code like this (untested):
extends KinematicBody2D
export (Path2D) var patrol_path = null
var patrol_path_node
var patrol_points
var patrol_index = 0
var target
const MOVE_SPEED = 1
var velocity
func _ready():
if (patrol_path != null):
patrol_path_node = get_node(patrol_path)
patrol_points = patrol_path_node.curve.get_baked_points()
# I am not sure whether this is in world space or not. I think it is
# in local space, so it needs to be converted.
target = patrol_points[patrol_index] + patrol_path_node.global_position
func _physics_process(delta):
var direction_to_target = target - global_position
velocity = direction_to_target.normalized() * MOVE_SPEED
velocity = move_and_slide(velocity)
if (global_position.distance_to(target_global_position) < 50):
patrol_index += 1
if (patrol_index > patrol_points.size()):
patrol_index = 0
# I am not sure whether this is in world space or not. I think it is
# in local space, so it needs to be converted.
target = patrol_points[patrol_index] + patrol_path_node.global_position
I have no idea if the code above will work or not, but I think something like that is how you can use a Path2D to move from point to point.