Move on Path2D (Pathfollow)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By FeyGaming

Hi guys,

how is it possible to walk on a line or path only like in “Super Mario World” for SNES to get from level to level?

I tried to hook up my KinematicBody2D with area_entered to “walk” along the Path, but it goes only oneway. An when I entered the Area2D I, have to leave the Area2D before i can enter a second time.

Do you have some ideas?

Thanks a lot.

1 Like
:bust_in_silhouette: Reply From: njamster

Well, if you’re using Path2D- and PathFollow2D-nodes (as both the title and the tags suggest you do) it’s rather simple: all you have to do is translate the player inputs into offsets along the path - either forward or backward.

func _physics_process(_delta):
	if Input.is_action_pressed("ui_right"):
		$Path2D/PathFollow2D.offset += 1
	elif Input.is_action_pressed("ui_left"):
		$Path2D/PathFollow2D.offset -= 1

	$Player.position = $Path2D/PathFollow2D.position
:bust_in_silhouette: Reply From: jolleyronald360

All things considered, in case you’re utilizing Path2D-and PathFollow2D-hubs (as both the title and the labels recommend you do) it’s somewhat basic: you should simply make an interpretation of the player contributions to counterbalances along the way - either forward or in reverse.