There’s a certain amount of craftsmanship involved in making things move around algorithmically. Getting a camera to slide smoothly into position, gliding on the gossamer wings of math, can be a perilous undertaking. One wrong wobble, one tiny pop, and every pixel on the screen becomes wrong, the needle slides off the record, and the magic spell is broken.
Enter one of my favorite tools in the Unreal Engine toolbox: the InterpTo() functions, available in C++ or in Blueprints.
They exhibit fast exit behavior, accelerating instantly. They have a silky smooth arrival characteristic, and they terminate without a noticeable pop in a reasonable timeframe.
They’re great for smoothing out discontinuities. They can deliver a sense of momentum and “weight”.
They’re perfect for interpolations with an indeterminate endpoint. Try setting up a “pursuit” scenario – your actual value ever-interpolating toward the ideal goal value – and you’ll get a satisfying and highly tunable “flexiness”.
They’re framerate-independent. Enough, anyway.
They’re fun at parties.
In short, they’re a valuable tool in the Unreal Engine toolbox and worth getting to know. And as always, if you have any questions or inspiring interpolation-related anecdotes to share, comment below!
Is it possible to choose different interpolation functions, i.e. ease-in, ease-out, ease-in-ease-out, linear… etc.? I only see one function for each variable type.
I’d love to see that as well. InterpTo’s have been working great for me, but I’d love to be able to refine some of the motions using eases, etc. as gregdumb mentioned.
There are a bunch of other interpolation options that serve different needs. The InterpTo functions are nice for many circumstances but certainly not all.
If you have a known interpolation duration, there are plenty of other options in UnrealMathUtility.h. One I like in particular is InterpEaseInOut, which gives you a nice S-style curve and a single number to tweak the acceleration and deceleration.
Check out the graph here (look at the blue for x<0.5, red for y>0.5). You can play with the exponents in the equations to see how the curve changes shape for various Exp values.
Ooh nice, so many interp functions there! Now I’m just trying to wrap my head around all of them, lol.
You mentioned using a known interpolation duration – how exactly would I do this? I guess I would need to calculate my own Alpha values, using deltatime or something? Is there a built-in function that does this already?
And, would it be too much to ask for some examples of these functions in use?
Further to gregdumb’s question, I’d also like to know InterpSpeed is defined (i.e. is it UnrealUnits per second, or something more abstract). I also had a difficult time getting my head around this in UDK and basically had to resort to trial and error. Is the value defined? If it is, it’s not mentioned in the code comments. Thanks.
If you have it running on a tick, you can set a boolean variable like IsInterpingTo and a Branch node. You custom event can set the boolean and possibly the TargetValue variable as a passed value
This is your “percentage complete” for your interpolation. Update your alpha every frame and use it in your InterpEaseInOut function. Keeping the TotalInterpTime fixed is the easiest way to ensure smooth motion. If you change that in a discontinuous manner, you’ll get a pop in your motion.
I looked and we don’t really have any usages to point to in the samples. Something I’ll keep in mind next time I do one though!
I guess it’d be something like “percentage of remaining distance to travel per second”, with the units being 1/sec. But I’ve always thought of it an abstract value that I could tweak to change the feel.
Good idea. I submitted a change today to expose InterpEaseInOut for floats to BPs. If you’re using the source, it should be easy to follow the same pattern to expose other functions as well.
For a derpy but fun example simply swap out the “GoalSphere” actor for “GetPlayerCharacter” in their blueprint example. The PhysicsSphere will follow your character around like a little flying companion droid or fairy.
Where is this method defined in C++? I have no idea how to include in project and searching on github on the repository reveals no leads Thanks in advance!