0 votes

I have been trying to get the player to move to x point without input from the player. I have tried many things but settled on just the lerp function. but run into a few issues with it so far. I have sort of got it to start working but it will not go up on the y axis.

        direction.y = lerp(global_position[1], hook_position[1], 0.009)
        direction.x = lerp(global_position[0], hook_position[0], 0.009)

I have already made sure that I effectively turn off the gravity in the scene, I also have checked to make sure that the positions for both global_position and hook_position are valid.
(note this is all in 2d)
Thanks for any help you can provide!

Godot version Godot v3.4.4
in Engine by (38 points)

One option that you might or might not have tried already is to use a tween for this.

You could add this to your player node:

var tween

func _ready():
    tween = Tween.new()

and then when you want to move automatically (over a duration of, say, 1.5 seconds) you can run this on the player node

tween.interpolate_property(self, "global_position", global_position, hook_position, 1.5)

The syntax for the interpolate_property function is:

(Node with property you want to lerp, Name of property you want to lerp, Initial value, Final value, Duration)

Also, it's not exactly a lerp, since it eases in and eases out to make the motion not be jerky at the start and finish.

Please log in or register to answer this question.

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