The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

I have the float variable extension and want it to be interpolated. How? I only know that Tweens can interpolate properties of Nodes but I need an interpolation of a script's variable.

Godot version 3.2.3.stable
in Engine by (382 points)

1 Answer

+1 vote

You can use the lerp function. For example, you could have a value named x that is 0, and you could interpolate it to 100 using this:

x = lerp(x, 100, 1)

The first value in the lerp function is the starting value, so I just set it to what x is starting at. The second value in the ending value, so I put it too 100. The last value I believe is the percent of the way you want it to lerp every frame, but I’m not 100 percent sure on that. I do know that increasing it will make your lerp happen faster. In your case, you could do:

extension = lerp(extension, endValue, percentPerFrame)

Obviously but the values you need in, but I think you get the point. I hope this helps!

by (599 points)

That's good but when I call this neither in _process(delta) nor in _physics_process(delta), it jumps directly to the end value but I have things going on in the functions already and surely I want the lerp not to be called all the time, so what to do? Changing a specific variable when I want to call this and always check for this variable in _process(delta)? Meh

I’m confused when you want to call this then. This would be no different that interpolating it, so you should call it when you would interpolate it. As for why it is jumping to the end, I have no idea. Just try and put the third value at something really low like 0.01 to test. Sorry for not being much help.

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 [email protected] with your username.