@Pefistep said:
Yeah, I had that script in the base Node2D, if you attach it to the Path2D node you have to change that line to "get_node("PathFollow2D")", or you can just attach the script to the PathFollow2D itself, in which case:
extends PathFollow2D
var speed = 200
var direction = 1
func _process(delta):
if unit_offset == 1.0:
direction = -1
elif unit_offset == 0.0:
direction = 1
offset += speed * delta * direction
I'm still familiarising with Godot, and I wasn't sure about the path for PathFollow2D. It's fixed now and works good.
I used an animated sprite, with two small additional lines of code, the sprite flips when reaching the ends of the path - just in case anyone else needs to know ;)
extends Path2D
onready var patrol_path = get_node("PathFollow2D")
var speed = 200
var direction = 1
func _process(delta):
if patrol_path.unit_offset == 1.0:
direction = -1
$PathFollow2D/AnimatedSprite.flip_h = false ## Flip Animated Sprite Direction
elif patrol_path.unit_offset == 0.0:
direction = 1
$PathFollow2D/AnimatedSprite.flip_h = true ## Flip Animated Sprite Direction
patrol_path.offset += speed * delta * direction
Here's my node tree:

I set the Animated sprite to play from the Inspector, but you could easily play the animation from withint the script.
Here's an example screenshot:

The path method here is really useful as you can make the path go in any direction obviously, not just horizontally.
Although I'm not sure how resuable it is for adding more than one if you have them in different scenes.