# I'm not getting FLerp, FInterpConstantTo, FInterpTo

Hello There!!

In lecture no. 101 I’m still pretty confused and not getting the lecture.

I just want to know what they do, we we use them, when should be use them. I haven’t got the syntax too. “FMath::FInterpTo(CurrentYaw, 70.f, DeltaTime, 2);”, What does DeltaTime mean here and all sorts of that stuff.

It would be really nice if someone explains me this. Please be a bit descriptive, I’m still a beginner.

Thanks for reading,
BYE!!

`FMath` is a class with static member functions, meaning you don’t need an instance of `FMath` to call it.

``````class Example
{
static int GetStatic() { return 10; }
int GetNonStatic() { return 20; }
};

int main()
{
int V1 = Example::GetStatic(); // V == 10
int V2 = Example::GetNonStatic(); // Error! GetNonStatic needs an instance of Example
Example E;
int V2 = E.GetNonStatic(); // 👍
}
``````

The time since the last frame.

Lerp is just a linear interpolation between 2 values.

``````FMath::Lerp(5, 10, 0.5);
``````

Would return 7.5 as that is half way between 5 and 10.

``````FMath::Lerp(5, 10, 0.25);
``````

Would return 6.25 as that is a quarter of the way between 5 and 10.

`FMath::InterpTo` interpolates between two values using a delta time and speed to calculate the values. It starts strong and eases out. e.g. (using between 5 and 10 again and some unknown speed/deltatime)

``````5
7       # diff of 2
8       # diff of 1
8.5     # diff of 0.5
8.75    # diff of 0.25
``````

`FMath::InterpConstantTo` interpolates between two values with a constant step e.g.

``````# always +1
5
6
7
8
9
10
``````
1 Like

Hi @DanM

Thank you so much, this gave me a better understanding of what lerp, FInterpConstantTo and
FInterpTo do. I’ll try to explain what they do-

Lerp-

FMath::Lerp(9, 20, 0.5) = 14.5

FMath::InterpTo(9, 20, x, y) -

9
14 # diff of 5
17 # diff of 3
18.5 # diff of 1.5
19.5 # diff of 1
20.0 # diff of 0.5

FMath::InterpConstantTo -

9
10
11
12
13

18
19
20

Correct me if I 'am wrong anywhere. If not then please tell me that too.

Thanks for helping,
BYE!!

1. Yes.
2 & 3. Kind of. My example was just a hypothetical output, the actual result would depend on the values of delta time and speed. The step for ConstantTo could be any amount for example like 2 or 5, it will just remain constant throughout the interpolation.

Also I forgot to mention that the first argument for the latter two is intended to be the previous (technically current) value.

e.g.

``````float Current = 90.f;
for (int i = 0; i < 10; ++i)
{
// or FMath::InterpConstantTo
Current = FMath::InterpTo(Current, 360.f, ..., ...);
}
``````

Which is what is happening via tick and not a loop by updating the member variables value.

1 Like

Hi @DanM

I’ve read your post and came up with the conclusion that FMath::InterpConstantTo or FMath::InterpTo
are loops, but they use ticks instead of any integers. But lerp is different. It does its stuff with the given values and alpha(basically finding that alpha between the numbers).

Correct me if I’m wrong. If you think I’m wrong with FMath::Lerp then I just don’t get the right words to describe it.

Take Care,
BYE!!

They are not. They are mathematical formulas just like Lerp. Lerp is different because you give it a point A, a point B and some alpha T that is between 0 and 1 and gets you the point between A and B with respect to the value of the alpha.

The other two you give it the current value, the target value, delta time, and speed. You then use the returned value to update the current value. We do that via tick but you can use loops just as well.

Example:
Compiler Explorer

First 10 values of each using a randomly chosen value for delta time.

1 Like

Hello @DanM

I’ve finally got it now! Lerp just gets the alpha between 2 given values. Other two use ticks to update the current value.

Take Care,
BYE!!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.