Download

Question: How to get a curve to lerp like a timeline?

Hello all! I am using C++ and was wondering if it is possible to get a curve asset (a float curve) to lerp like a timeline would for a smooth transition, and yes I already posted about this on the Answerhub but got no confirming answers. Thanks in advance! -Ian

Hi!
I’m sure it’s possible, but you’ll have to specify exactly what it is you want the lerp to achieve. It’s not necessarily mandatory you use a curve asset.

Here are the Interpolation functions I use in my noise generation library. Hope it helps.


float UNoiseInterp::CubicInterp(float n0, float n1, float n2, float n3, float a)
{
	float p = (n3 - n2) - (n0 - n1);
	float q = (n0 - n1) - p;
	float r = n2 - n0;
	float s = n1;
	return p * a * a * a + q * a * a + r * a + s;
}

float UNoiseInterp::LinearInterp(float n0, float n1, double a)
{
	return ((1.0 - a) * n0) + (a * n1);
}

float UNoiseInterp::SCurve3(float a)
{
	return (a * a * (3.0 - 2.0 * a));
}

float UNoiseInterp::SCurve5(float a)
{
	float a3 = a * a * a;
	float a4 = a3 * a;
	float a5 = a4 * a;
	return (6.0 * a5) - (15.0 * a4) + (10.0 * a3);
}

Hmm. I would recommend you have a look at the FMath Library, It’s what I use and it covers all my lerpy needs

Thank you all for the responses! I am trying to get the camera view to move to the side slowly without a matinee, I thought a curve would help because I consider it to be somewhat like a timeline.

It shouldn’t be too hard, again, using the FMath library.
If you have a target location and rotation, I’d set it like this;



void AYourClass::MoveCameraWithSomeSweetLerps(UCameraComponent* Camera, FVector& TargetLocation, FRotator& TargetRotation, float Speed, const float DeltaTime) {

/* Location Lerp */
Camera->SetWorldLocation(FMath::VInterpConstantTo
(
   Camera->GetComponentLocation(), // Camera's current world position
    TargetLocation,                           // Target Location for the camera
    DeltaTime,                                 // DeltaTime 
    InterpSpeed                               // How long the interpolation should take
);
/* Rotation Lerp */
Camera->SetWorldRotation(FMath::RInterpConstantTo
(
    Camera->GetComponentRotation(), // Camera's Current World Rotation
    TargetRotation,                            // Target Rotation for the camera
    DeltaTime,                                  // DeltaTime
    InterpSpeed                                // How long the interpolation should take
);
}



Have’t tried this, but feel free to copy and paste and sort out any syntax errors :slight_smile:

Not exactly what I was going for. I am trying to lerp a and use that value to move the camera, thanks for the comment though. :slight_smile: How would I get a curve value that is updating each time, lets say, the W button is pressed.

Then I’m not really sure what you’re after.
If you want the camera to move from one place to another smoothly, the code I supplied you does just that. Are you sure that you’re sure what a lerp is? You can bind the function I supplied to run when W is pressed, just supply it with DeltaTime.

I am trying to make recoil of sorts, and I have found a solution (Its basically using an add yaw input.). But thanks for all the help.