0 votes

How can I interpolate (over time, as in animate) between 2 values in a function that is not a process function?

I can't use a tween because that requires an object. There is no object - there are simply 2 values which are Vector3's (from and to).

Neither interpolatewith nor lerp would work either as these must be in process or physicsprocess and called on every frame to work.

Can I somehow do that by looping though an array of positions between from and to?

Godot version 3.4
in Engine by (431 points)

You must call the function repeatedly in some fashion to progress over time; be that in process or from a timer, maybe a background thread or coroutine. Perhaps it'd be more appropriate to use a Tween or an animation? Perhaps more information would help; what are you trying to achieve?

1 Answer

0 votes

Sorry, I don't understand. When you say "there is no object", how is this possible? Godot is OOP, everything is an object. If you've got a node in the tree, you've got an object instance.

Just add a tween as the child of whatever node your script is attached to and call $Tween.interpolate_method passing self and the target method in your script along with the values you want to interpolate between. Then just pick up the values in the target method and you're good to go.

by (1,473 points)

$Tween.interpolate_method passing self and the target method in your
script along with the values you want to interpolate between.

Well that's the thing. I don't really know how interpolate_method works. I thought this could be the way to go. Docs are somewhat scant on this. I tried doing something similar to what you described but it didn't work (although I used a dummy spatial as 'object'; i will try again with 'self'; maybe I'm getting the syntax wrong on this one too, will try again tonight).


Would love to see an example of interpolate_method. Can't get this to do anything. Found no examples on google...

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.