+1 vote

Is there a way to use lerp() function with a KinematicBody2D within a C# script?
There was nothing found in the docs.

in Engine

9

Linear interpolation (lerp) is actually a pretty easy function to implement. The equation is

``````float Lerp(float firstFloat, float secondFloat, float by)
{
return firstFloat * (1 - by) + secondFloat * by;
}
``````

A higher order Lerp just wraps lower order lerps:

``````Vector2 Lerp(Vector2 firstVector, Vector2 secondVector, float by)
{
float retX = Lerp(firstVector.x, secondVector.x, by);
float retY = Lerp(firstVector.y, secondVector.y, by);
return new Vector2(retX, retY);
}
``````

The DirectX SDK has all manner of math functions like Unity, but that's a lot of overhead to bring in just for Lerp. You're probably best off just implementing your own.

by (22 points)

Thank you. :)
Why is this then not simply implemented in Godot to provide it... ?! ;)

Are there more stuff, which needs to be implemented by our self, which is missing in C# implementation instead of GDScript?

These issues should be also documented or better implemented in any way to increase equality of the C# implementation.

In that case I also missing:
- the GDScript support for directly accessing the sub-nodes with "\$variable"

Should I place these requests at github?

Use Mathf.Lerp

+1 vote

If you dont want to implement your own, Godot implemented `Mathf` :)

``````Mathf.Lerp(firstFloat, secondFloat, thirtdFloat);
``````

I was looking for `clamp` and `lerp` functions when I found this, please refer to the following reddit thread:

This is a quick quote from it:

Mathf and GD are from Godot library, only available when using Godot.
Mathf is for math functions, and GD for non-math functions. Mathf is
optimised for fast approximate results (not for high precision
computations).

by (16 points)