How to lerp/smoothly move a MeshInstance?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By RobotUnderscore
:warning: Old Version Published before Godot 3 was released.
extends MeshInstance

func _ready():
	set_process(true)
	var player_loc

func _process(delta):
	
	var player_loc = get_global_transform()
	
	if Input.is_action_pressed("inp_up"):
		player_loc.origin = linear_interpolate(Vector3(-0.5,0.25,-0.5), delta)
	else:
		player_loc.origin = linear_interpolate(Vector3(-0.5,0.0,-0.5), delta)
	
	set_global_transform(player_loc)

I want to smoothly move a 3D object from one point to another depending if a key is down or up.

Unfortunately, linear_interpolate() doesn’t exist for the Transform class.

How else can I have my object move smoothly?

EDIT: In conjunction with Zylann’s answer: if you want to use this code too but you find the interpolation too slow, change each of the deltas in the linear_interpolate()s to delta*25 or some other number, depending on the speed you’d like.

:bust_in_silhouette: Reply From: Zylann

linear_interpolate is a method of Vector3 because it needs to interpolate between the vector and the other, so you have to write player_loc.origin = player_loc.origin.linear_interpolate(Vector3(-0.5,0.25,-0.5), delta).

Yep, that worked! Thanks

RobotUnderscore | 2017-01-27 16:52