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
Announcement
Collapse
No announcement yet.
Question: How to get a curve to lerp like a timeline?
Collapse
X
-
Here are the Interpolation functions I use in my noise generation library. Hope it helps.
Code: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); }
Comment
-
Hmm. I would recommend you have a look at the FMath Library, It's what I use and it covers all my lerpy needs
Comment
-
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;
Code: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 ); }
Comment
-
Originally posted by Designer102 View PostNot 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.How would I get a curve value that is updating each time, lets say, the W button is pressed.
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.
Comment
-
Originally posted by MPalacios View PostThen 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.
Comment
Comment