Changing position smoothly

Godot Version

v4.2.2.stable.arch_linux

Question

I’m trying to make a subways surfers styled game, and i’ve gotten to a point where i’m overthinking things. Currently, the code that i know pertains to the situation im having looks like this:

var positions: Array = [-3,0,3]
var curPos = 1
func _process(delta):
	swipe()
	if swipeDir == 1:
		if curPos < 2:
			curPos += 1
			position.x = positions[curPos]
			swipeDir = 0
	elif swipeDir == -1:
		if curPos > 0:
			curPos -= 1
			position.x = positions[curPos]
			swipeDir = 0

I for the life of me cant figure out how to move it using lerp. I know i have to change the position.x = positions[curPos] to use lerp or interpolation, but everything I try ends up erroring out.

it is possible with lerp or tween, which error did shows when you used lerp?

Sorry for the late reply, i was trying to Vector3 a single vector (position.x). I changed position.x = positions[curPos] to set_physics_process(true) and wrote inside physics process:

func _physics_process(_delta):
	progress += speed
	if progress>= 1.0:
		end_swipe()
	else:
		position = position.lerp(Vector3(positions[curPos],4,0), progress)

end swipe is:

func end_swipe():
	position = Vector3(positions[curPos],4,0)
	set_physics_process(false)
	progress = 0.0