Godot 4.0: Tween Help

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

Converting from 3.5.2 to 4.0 and need help on changing two lines of old interpolation code to 4.0 syntax/methods:

@export var move_direction = "Horizontal"
@export var move_distance = 192
@export var speed = 3.0

var move_to = null
var follow = Vector2.ZERO

@onready var platform = $Platform #CharacterBody2D
@onready var tween = create_tween()

func _ready():
	if "Horizontal" in move_direction:
		move_to = Vector2.RIGHT
	elif "Vertical" in move_direction:
		move_to = Vector2.UP
			
	move_to *= move_distance
	_init_tween()

func _init_tween():
	var duration = move_to.length() / float(speed * 128)

	tween.interpolate_property(self, "follow", Vector2.ZERO, move_to, duration, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT, IDLE_DURATION)
	tween.interpolate_property(self, "follow", move_to, Vector2.ZERO, duration, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT, duration + IDLE_DURATION * 2)
	tween.start()

The parameters are vars I have setup and work correctly. The scene is a moving platform that I had working in 3.5.2.

:bust_in_silhouette: Reply From: keidav

Figured it out:

extends Node2D

@export var move_direction = "Horizontal"
@export var move_distance = 192
@export var speed = 3.0

var move_to = null
var follow = Vector2.ZERO

@onready var platform = $Platform
@onready var tween = create_tween()

func _ready():
	if "Horizontal" in move_direction:
		move_to = Vector2.RIGHT
	elif "Vertical" in move_direction:
		move_to = Vector2.UP
			
	move_to *= move_distance
	_init_tween()

func _init_tween():
	var duration = move_to.length() / float(speed * 128)

	tween.bind_node($Platform)
	tween.set_loops()
	tween.set_ease(Tween.EASE_IN_OUT)
	tween.tween_property(self, "follow", move_to, duration).from(Vector2.ZERO)
	tween.tween_property(self, "follow", Vector2.ZERO, duration).from(move_to)
	
func _process(_delta):
	platform.position = platform.position.lerp(follow, 0.075)