# Moving Actor back and forth using lerp(vector)?

Hello, I’m trying to make an actor move from left to right using lerp rather than timeline because I’m trying to create a simple enemy. So far I’m stuck at getting the actor to move back and forth below is my blueprint and thanks for the help!

Hello ,

When using a Lerp, the Alpha determines what the lerp outputs as well as the A and B. If the Alpha is 0, it’ll output A and if it’s 1, it’ll output B. If it is set to any fraction between, it’ll output that point between those two vectors. As an example, if you put 0.5 for the alpha, it’ll do half way between the two points. If you need help with setting up the alpha value you need, please let me know.

Hope this helps!

I do need help with setting up the alpha value, I’m attempting at have it interpolate back and forth from 1 to 0 but I have no idea how.

I know you said that you didn’t want to use timelines but using a timeline would be the easiest way to go about this. I’m sure there are other ways the reverse looping part, especially with Event Dispatchers but I’m going to keep it simple.

First, a screenshot of the nodes:

First part is simple, setting up the initial and destination values. I have mine just moving upwards 300 units. Inside of the timeline, I just have a Float curve with 2 keys. The first key is set to value 0, time 0. The second key is set to a value of 1 (the max for the alpha for the Lerp) and 3 time, to make it take 3 seconds to travel. Be sure to set the Length to 3 (or the time you choose). I then plugged the output into the lerp’s alpha. After that I had to set up how it loops backwards. I figured it’d be easiest to use a boolean so I made a boolean that is true by default. When it finishes the timeline the first time, it’ll check the boolean, find that it is true, set it to false, and then reverse the timeline from the end. The next time it’ll to the opposite and this creates the looping movement.

The benefit to this is that you’re setting this all up on beginplay instead of constantly calling it on Tick. This way it’ll be more performant and also won’t be framerate dependent.

Thank you this was extremely helpful!

How would you go about this if you want to set the time it takes with a variable ? Can We create timelines at runtime or alter it’s speed ?

How to setup an interpolation with getWorldDeltaSeconds ?

nevermind, found the vInterpTo node…

1 Like

@Matthev J You should use Flip Flop instead of these get and set boolean nodes.