Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | RobotUnderscore | |
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.