+1 vote
extends MeshInstance

func _ready():
    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)
        player_loc.origin = linear_interpolate(Vector3(-0.5,0.0,-0.5), delta)


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.

in Engine by (30 points)
edited by

1 Answer

+4 votes
Best answer

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).

by (28,833 points)
selected by

Yep, that worked! Thanks

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.